Skip to content

describe(error) error-formatting helper is copy-pasted verbatim across 5+ modules #89

Description

@Deepam02

Problem

The identical helper

function describe(error: unknown): string {
  return error instanceof Error ? error.message : String(error);
}

is defined separately in five modules, and the same expression is also inlined in a few more — there is no single home for "stringify an unknown error".

Verbatim describe copies:

  • packages/agentctx/src/hooks/lifecycle.ts:83
  • packages/agentctx/src/hooks/session-start.ts:90
  • packages/agentctx/src/hooks/user-prompt-submit.ts:114
  • packages/agentctx/src/extract/ingest.ts:230
  • packages/agentctx/src/extract/run.ts:194

Same expression inlined (not via a helper):

  • packages/agentctx/src/consolidate/run.ts:57error instanceof Error ? error.message : String(error)
  • packages/agentctx/src/mcp/server.ts:75 — same
  • packages/agentctx/src/mcp/tools.ts:464 — same (in callTool's fallback)

This is the same kind of duplication already tracked for projectId.slice(0, 12) in #79.

What done looks like

  • One shared helper (e.g. describeError(error: unknown): string in a small new packages/agentctx/src/errors.ts, or alongside an existing dependency-free util) is the only definition.
  • The five describe copies are deleted and import the shared helper; the inlined ternaries are switched to it too.
  • No behavior change — npm run check stays green. Bonus: a one-line unit test covering the Error and non-Error branches.

Scope: mechanical, single concern, no architecture impact — a good first contribution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions