Skip to content

Shared helper: errorMessage for the error-message unwrap #1442

Done

Description

@V3RON

Part of #1840.

Scope

One shared errorMessage helper in a new leaf module src/shared/ (small
pure helpers; errorMessage is its first). Every hand-written copy of
function errorMessage(error: unknown): string under src/ is deleted, the
CLI's included, and every inline
error instanceof Error ? error.message : String(error) in non-test src/
calls the helper. A repo test refuses a new copy. No behaviour change.

It does not split: the copy check refuses every copy left, so it lands with
the last conversion. It touches 21 src/ modules (the 19 with sites, http
for its copy, and the new shared), all with the same one-line edit.

A user notices nothing; if this goes wrong, an error's text changes somewhere
(a CLI line, a log line, an HTTP message).

Technical spec

Commit 200afe5.

Rows

  • Behaviours: B1, B2, B3, B4, B5, B6
  • Interfaces: I1, I2
  • Existing code: X1, X2, X3, X4, X5, X6, X7, X8, X9, X10

Facts

# Fact Source
F1 src/shared/ does not exist. A directory under src/ with an index.ts is a component from its first commit, entered only through its index. .dependency-cruiser.mjs:1-12, .dependency-cruiser.mjs:34-43
F2 oxlint is 1.74, and its rule set has no no-restricted-syntax, so no lint rule can match the expression. The precedent for a source-wide ban is the time outside src/ports/ in src/lint-rules.test.ts: it lists git ls-files sources, drops a directory and the tests, and matches over blankSource(text, { strings: true }), which blanks comments and string text and keeps ${} code. package.json:113; strings oxlint.darwin-arm64.node of @oxlint/[email protected] | grep -oE 'no-restricted-[a-z]+' → exports, imports, jest, matchers, types, vi; src/lint-rules.test.ts:920-947; src/test-support/source-text.ts:6, src/test-support/source-text.ts:30-31
F3 pnpm lint runs oxlint and dependency-cruiser over src e2e ui packages, and pnpm check runs it with the tests. The unwraps outside non-test src/: src/leasing/lease-request-book.test.ts:168, src/gateway/relay-failures.test.ts:33, ui/src/state/screen.ts:171, ui/src/data/stream.ts:414, e2e/helpers/wait.ts:47, e2e/helpers/env.ts:76 (inside a private copy at e2e/helpers/env.ts:75), packages/e2e/src/errors.ts:25. packages/ never imports src/. package.json:66, package.json:73; grep -rnE of the unwrap pattern over src test files, ui, e2e, packages; .dependency-cruiser.mjs:104-111
F4 The dependency rules are proved in src/lint-rules.test.ts: one dependency-cruiser run over pathCases, each a list of fails/passes imports. src/lint-rules.test.ts:129, src/lint-rules.test.ts:285-300
F5 Every module under src/ needs a manual with a Does: line beside a CLAUDE.md holding only @AGENTS.md, linked from the architecture map; all manuals together fit in MANUALS_TOTAL_CHARACTERS (160,000; about 144,000 used). src/docs-manuals.repo.test.ts:11, src/docs-manuals.repo.test.ts:117-129, src/docs-manuals.repo.test.ts:165, src/docs-manuals.repo.test.ts:214; docs/internal/ARCHITECTURE.md:35-74
F6 agent-identity imports nothing and has no rule of its own; its helper is a plain exported function, and its unit test is the model for the new one. src/agent-identity/AGENTS.md:7; src/agent-identity/index.test.ts
F7 Nothing here touches src/contract/, so .agents/scripts/protocol-bump-check.mjs and its NOT_SHAPES are unaffected. protocol-bump-check.mjs counts only src/contract/*.ts

Modules touched

Home: shared, new — src/shared/index.ts, src/shared/error-message.ts
and its unit test, AGENTS.md and CLAUDE.md. The manual holds the
admission rule:

  • Does: small pure helpers two or more components use.
  • A helper goes in only if it is pure (no I/O, no clock, no state), imports
    nothing (no component, package or Node module; dependency rule
    shared-imports-nothing), and is used by two or more components. Anything
    else lives in the module that owns it.
  • errorMessage is the one error-message unwrap; the copy check in
    src/lint-rules.test.ts refuses another.

Sites (X1, X2, X4): core, drivers, gateway, daemon, agent-device,
ports, leasing, simlock-client, tunnel, stream, lease-files,
history, cli, updater, state, modules, mcp, host-load,
fseventsd, plus http (a copy and its importer only).

Rules and docs: .dependency-cruiser.mjs (I2, X10), src/lint-rules.test.ts
(B2, B3, B4), docs/internal/ARCHITECTURE.md (a module row, a dependency
row, X7's and X10's rows), X7's manuals, and
docs/internal/agent-rules/architecture.md rule 18 with
docs/internal/agent-rules/always-in-scope.md item 9 (X9).

Untouched: ui/, e2e/, packages/ and test files (F3).

Searches: the unwrap grep of #1840's Existing code, its whitespace-tolerant
twin and the function errorMessage grep for the sites; an import scan of
errorMessage for X4; .dependency-cruiser.mjs and .oxlintrc.json for
every rule naming a site module (X5, X6); the manuals of every site module
and docs/internal/ for claims about what a module imports (X7).

Rules in play

  • architecture rule 10 — "A rule is enforced in exactly one place": one
    unwrap in place of ten definitions and 95 inline copies, and the copy
    check keeps it one. ui/, e2e/ and packages/ keep theirs (F3).
  • architecture rules 4 and 14 — shared is a component with an explicit
    surface, its index.ts. It imports nothing, so it sits in no cycle.
  • architecture rule 15 — shared depends on nothing, so any module may
    depend on it, optional or required.
  • architecture rule 9 — a pure function needs no port; the manual's
    admission rule keeps I/O out.
  • architecture rule 18 — this task amends it (X9): a module that imports
    nothing and that no host wires exports its pure functions directly, as
    shared and agent-identity (F6) do.
  • architecture rule 13 — X7's manual lines and rule comments are fixed in
    the same change.
  • architecture rule 17 — any comment added to .dependency-cruiser.mjs or
    the test starts with why:.
  • ADR 0027 — the new rule lives in .dependency-cruiser.mjs, and
    src/lint-rules.test.ts proves each new or changed rule fires (F4).
  • documentation rule 7 — the new manual opens with Does:, sits beside a
    CLAUDE.md that holds @AGENTS.md, and fits the manuals' budget (F5).
  • ADR 0077 §3 — packages/ never imports src/, so
    packages/e2e/src/errors.ts keeps its unwrap (F3).

Tests

Seam: src/lint-rules.test.ts — its pathCases (F4) and
the time outside src/ports/ (F2) as models; the helper's own test is
modelled on src/agent-identity/index.test.ts.

  • B1: errorMessage of an Error, a SimlockError, a string, a number and
    undefined.
  • B2: a file in src/shared/ importing ../core/index.js, zod (unbuilt)
    and node:path fails; one importing ./y.js passes.
  • B3: src/cli/errors.ts importing ../shared/index.js and
    ../agent-identity/index.js passes, ../ports/index.js fails; a file in
    src/updater/ and one in src/modules/ importing ../shared/index.js
    pass.
  • B4: the copy check over every git ls-files source under src/ but
    src/shared/ and *.test.ts(x); a sample proves it counts a one-line
    unwrap, one split over lines, one inside ${}, and not one in a comment
    or a string.
  • B5: src/cli/lazy-loading.test.ts passes unchanged, and the suite under
    pnpm check passes.
  • B6: src/docs-manuals.repo.test.ts passes with the new manual; rule 18,
    X7's and X10's lines read true.

Done when

  • src/shared/ exists with an index.ts exporting errorMessage, an
    AGENTS.md holding the admission rule of Modules touched, and a
    CLAUDE.md holding @AGENTS.md; docs/internal/ARCHITECTURE.md's module
    table has a shared row linking that manual, and its dependency table has
    a shared-imports-nothing row.
  • .dependency-cruiser.mjs has shared-imports-nothing and
    shared-imports-nothing-unresolved, and
    cli-router-imports-no-component-values, updater-imports-little and
    modules-imports-little allow src/shared/, and they and
    host-load-imports-ports-only say so in their comments.
  • Architecture rule 18 states the exception for a module that imports
    nothing and that no host wires, and always-in-scope item 9 agrees with
    it.
  • git grep -nE 'instanceof Error \? [A-Za-z_.]+\.message : String\(' -- 'src/*.ts' ':!*.test.ts'
    prints exactly one line, in src/shared/, and
    git grep -n 'function errorMessage' -- 'src/*.ts' prints exactly one
    line, in src/shared/. The two test-file unwraps of F3 remain.
  • src/mcp/connect.ts calls the shared helper and has no isSimlockError
    fast path of its own.
  • X7's and X10's manual lines, map rows and rule comments are true of the
    new imports.
  • src/lint-rules.test.ts holds the cases and the copy check of Tests, and
    src/cli/lazy-loading.test.ts passes unchanged.
  • pnpm check passes.

Out of scope

ui/, e2e/, packages/ and test files (*.test.ts) keep their unwraps
and are outside the copy check (F3). No other helper moves into
src/shared/. The .catch(() => undefined) idiom is not this helper's
business.

Depends on

Written by an agent.

Activity

  1. added
    task:draft
    on Nov 7, 2026
  2. V3RON commented on Nov 24, 2026

    @V3RON
    ContributorAuthor

    Maintainer decision (2026-11-24)

    Deliver it: one errorMessage helper in src/ports, the copies removed, and a lint rule. No behaviour change. Next: spec check, then task:ready.

    Written by an agent.

  3. V3RON commented on Nov 25, 2026

    @V3RON
    ContributorAuthor

    Body moved to today's task template as part of #1840. The design facts now sit in #1840's rows. Changes from the design check: the shared-imports-nothing rule has its own to and refuses packages and Node built-ins (the contract's rule lets them through). Architecture rule 18 gains an exception for a module that imports nothing and that no host wires (maintainer decision, 2026-11-25). The host-load rule comment and map row are fixed too. The body before this edit is kept in the issue's edit history.

    Written by an agent.

  4. added
    task:ready
    and removed
    task:draft
    on Nov 25, 2026
  5. self-assigned this
    on Nov 25, 2026
  6. added a commit that references this issue on Nov 25, 2026
    cc79ffe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

task:ready

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions