The Deska blog
Better Error Messages, Written by Agent
Learn how to use an AI agent to write better error messages that improve debugging workflows and developer experience in complex software systems.
· 9 min read
Writing better error messages is a critical yet often overlooked aspect of software engineering that directly impacts technical debt and maintenance costs. When a system fails, the quality of the feedback provided determines how quickly a developer can diagnose the root cause. Leveraging an AI agent to write better error messages allows teams to transform cryptic stack traces into actionable intelligence. By integrating these agents into the development workflow, you can ensure that every exception provides context, potential solutions, and clear paths for remediation without manually drafting every string.
The Anatomy of a Good Error Message
A high quality error message serves as a bridge between a system failure and a human solution. Most default errors are either too generic, such as internal server error, or too technical, like a raw memory address leak. Effective error communication requires three distinct components.
First, the message must state exactly what happened. This involves identifying the specific operation that failed. Second, it must provide the context of why it happened. This includes the state of the system at the time of failure. Third, it should offer a hint or a direct link to documentation on how to fix it.
Common Pitfalls in Error Handling
Many developers fall into the trap of writing messages for themselves rather than for their future selves or teammates. Examples of poor patterns include.
- Using obscure internal codes that require a manual lookup table.
- Failing to include the input data that caused the validation to fail.
- Exposing sensitive system information in production logs.
- Writing passive aggressive messages that blame the user or the caller.
How Coding Agents Transform Error Writing
Coding agents like Claude Code or OpenCode change the paradigm of error handling by treating error strings as dynamic documentation. Instead of a developer guessing the best way to explain a complex edge case, an agent can analyze the surrounding function logic and generate a precise description.
These agents excel at identifying the logical flow leading to an exception. When you prompt an agent to refactor a block of code, you can specifically instruct it to replace generic throw statements with descriptive, typed exceptions. The agent understands the variable names, the expected types, and the likely failure modes of the APIs you are consuming.
In a local-first environment, this process is even more efficient. The agent has direct access to your file system and can scan the entire project structure to ensure that error naming conventions remain consistent across different modules.
Comparative Workflow: Manual vs Agent Assisted
| Feature | Manual Writing | Agent Assisted |
|---|---|---|
| Speed | Slow and repetitive | Near instant generation |
| Consistency | High variance between devs | Unified style and tone |
| Context | Often lacks specific data | Deeply integrated context |
| Maintenance | Hard to update globally | Easy to refactor via chat |
Implementing Automated Error Improvement in Deska
Deska provides a unique environment for this task because it allows you to run multiple agents in parallel. You can open a terminal panel and a code editor side by side to observe how your application behaves in real time.
When a runtime error appears in your terminal, you can use Ask Deska to capture the output and send it to one of the coding agents. The agent can then suggest a specific code change to make that error more descriptive in the future. Because Deska uses an infinite canvas, you can keep the original error log visible in one panel while the agent works on the fix in a Monaco editor panel.
This workflow is particularly useful for legacy projects where error messages are non existent or misleading. You can point an agent at a directory and ask it to audit all catch blocks. The agent can then provide a list of suggested improvements that include the specific variables involved in the failure.
Managing Error Documentation via Mobile
Developing on the go is often restricted to monitoring, but the mobile connectivity in Deska allows for a different approach. If you are away from your desk and see a recurring error in your logs, you can use the secure relay to trigger an agent task.
You might instruct the agent to add more detailed logging to a specific function that is causing issues. This ensures that by the time you return to your workstation, you have the data needed to solve the problem. The ability to monitor and continue work ensures that the feedback loop between finding an error and improving its messaging is never broken.
Best Practices for Agentic Error Refactoring
When using agents to rewrite your error handling logic, follow these guidelines to maintain code quality.
- Define a schema for your errors. Tell the agent to follow a specific format, such as
[Component][ErrorLevel] Message. - Use typed exceptions. Agents can quickly generate custom exception classes that carry metadata.
- Keep it local. Ensure your data and storage stay on your machine by using agents that run against your local files.
- Review the output. Even the best agents can sometimes hallucinate logic, so always verify the suggested messages in the code editor.
FAQ
How to automate error message generation?
You can automate this by using coding agents to scan your repository for generic exceptions. By providing the agent with your project style guide, it can rewrite throw new Error() calls into specific, context aware messages that include relevant variable values.
Can AI agents fix production bugs?
While agents can suggest fixes based on logs, their most reliable use case is improving the observability of your code. They help you write better error messages and logs, which in turn makes it significantly easier for a human developer to identify and fix the actual bug.
Is it safe to share error logs with AI?
Safety depends on your configuration. When using a local-first tool like Deska with your own API keys, your code and files stay on your machine. However, you should still be careful not to include sensitive user data or credentials in the strings you send to an LLM provider.
Start Building Better Systems
Improving the way your application communicates failure is one of the fastest ways to increase developer velocity. By using specialized tools to handle the repetitive task of drafting messages, you free up your mental energy for complex architecture and logic. You can download the desktop app for your preferred platform at /download and begin organizing your workspace with side by side agents. Whether you use Claude Code or Codex, the infinite canvas provides the visibility needed to refine your codebase effectively.