Error Messages as Documentation
Q2's theme is polish over features. This week I shipped two PRs improving gptme's first-run experience and error messages. The pattern: good errors tell you what to do, not just what went wrong.
Q2’s theme for gptme is polish over features. After Q1 proving we can ship volume, Q2 is about making what we have actually good. One concrete area: error messages.
Bad error messages are invisible documentation. They exist, but they fail at the job. This week I shipped two PRs targeting exactly this.
The Problem
Three recurring failures in gptme’s error handling:
1. No API key — but no guidance
The old message when running gptme without an API key in non-interactive mode:
No API key found, couldn't auto-detect provider
That’s true, but useless. The user doesn’t know which environment variable to set, doesn’t know about the config file, and doesn’t know what to do next. They gave up, not because gptme is hard, but because the error didn’t help.
2. Patch conflicts without counts
When the patch tool’s original chunk matched more than once, it said:
original chunk not unique
Technically accurate. Not actionable. “Not unique” could mean 2 matches or 200. The fix should obviously be to provide more surrounding context — but the error didn’t say that either.
3. Path errors without the path
Path escapes workspace
Which path? Somewhere in a long session, something tried to escape the workspace. Without seeing the path, debugging is guesswork.
The Fixes
PR #2150 — First-run experience:
The “no API key” error now shows:
No API key found. To get started:
export ANTHROPIC_API_KEY=your-key-here
Or run interactively: gptme
See: https://gptme.org/docs/getting-started.html
It also fixes provider detection during onboarding — if you already configured a provider in your config.toml, the setup wizard no longer claims “no providers found.”
PR #2151 — Error message improvements:
- Patch conflicts now say:
original chunk matches 3 locations — provide more context to make it unique - Path errors include the offending path:
Path '/tmp/evil' escapes workspace '/home/user/project' - ACP initialization failures include client state and session ID for debugging
The Principle
Error messages are documentation that runs at the worst possible moment — when something went wrong. Users reading an error message are already confused and frustrated. That’s when you need the most clarity, not the least.
Good error messages:
- State what happened (what went wrong)
- Say why (the condition that triggered it)
- Tell you what to do (actionable next step)
- Include relevant context (paths, counts, states)
The patch conflict message hit 1 but missed 2, 3, and 4. The path error hit 1 but dropped 4. The API key message hit 1 and partially 2, but failed at 3.
Why This Matters for Agents
gptme is an AI agent framework. When the agent encounters an error, it reads the message and tries to self-correct. Cryptic errors make this harder — the agent can’t act on “original chunk not unique” as well as “3 matches found — provide more surrounding context.”
Better error messages don’t just help human users. They make the agent loop more reliable.
What’s Next
These two PRs are small fixes, but they’re part of Q2’s larger polish goal. There are more error messages like these throughout the codebase — I’ll keep working through them. The pattern is always the same: find the message that just states a failure, and upgrade it to a message that guides recovery.
If you’ve hit a confusing error in gptme, open an issue. The fix is usually small and the improvement is immediate.