Skip to content

Adopt shared errorMessage() in agents.ts and templates.ts - #608

Merged
selfcontained merged 1 commit into
mainfrom
tech-debt/adopt-error-message-helper
May 27, 2026
Merged

Adopt shared errorMessage() in agents.ts and templates.ts#608
selfcontained merged 1 commit into
mainfrom
tech-debt/adopt-error-message-helper

Conversation

@selfcontained

Copy link
Copy Markdown
Owner

Summary

  • Replaced 5 inline error instanceof Error ? error.message : "..." patterns in agents.ts with the shared errorMessage() helper from shared/lib/error-message.ts
  • Replaced 2 remaining inline patterns in templates.ts (which already imported the helper but wasn't using it everywhere)
  • This is a continuation of the tech-debt effort from PR Extract duplicate constraint-error handler in personalities.ts #602 which adopted errorMessage() in personalities.ts

Why this is tech debt

The shared errorMessage() helper was introduced specifically to eliminate this boilerplate. These 7 remaining inline instances were the last holdouts — using them inconsistently defeats the purpose of the shared helper and makes future changes (e.g., adding logging or changing the fallback behavior) require touching every file instead of one.

What's next

Next tech-debt run will tackle the top backlog item: monitoring the ide-settings.ts / agent-type-settings.ts pattern similarity.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@selfcontained
selfcontained merged commit a6b22f1 into mainMay 27, 2026
1 check passed
@selfcontained
selfcontained deleted the tech-debt/adopt-error-message-helper branch May 27, 2026 09:19
selfcontained added a commit that referenced this pull request Aug 9, 2026
`apps/server/src/shared/lib/error-message.ts` is the canonical helper for
turning an unknown catch value into a string, but 18 sites across 11
server modules had re-inlined `error instanceof Error ? error.message :
String(error)` instead of importing it. This is a regression of the
consolidation done in #608 — the pattern creeps back in every time a new
try/catch is written.
Replaced only byte-equivalent occurrences. Sites with a different
fallback ("Unknown error", "Archive failed", "Invalid model.", the
`.slice(0, 2_000)` truncation in browser-extension.ts) or a different
result type (the variants that rethrow an `Error` rather than produce a
string) are intentionally left alone — they are not the same function.
No behavior change; `errorMessage()` is byte-identical to what each site
inlined.
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@selfcontained