Skip to content

fix(core)(#191): promote errMessage helper; fix lossy NametagMinter stringification#192

Merged
vrogojin merged 1 commit into
mainfrom
fix/issue-191-error-stringification
Jun 8, 2026
Merged

fix(core)(#191): promote errMessage helper; fix lossy NametagMinter stringification#192
vrogojin merged 1 commit into
mainfrom
fix/issue-191-error-stringification

Conversation

@vrogojin

Copy link
Copy Markdown
Contributor

Summary

Fixes #191Sphere.init({ nametag }) failures surfacing as Submit failed: [object Object] instead of the aggregator's structured rejection.

  • Promote the existing errMessage helper from modules/payments/transfer/nostr-persistence-verifier.ts to core/errors.ts, next to redactCause / SphereError. The helper routes unknown-shape errors through redactCause + JSON.stringify, preserving field-level forensics while keeping W40 secret-byte redaction intact.
  • Replace the two highest-visibility lossy callsites in modules/payments/NametagMinter.ts (submit-retry catch at :182 and the outer mintNametag catch at :256) with errMessage(error).
  • Update nostr-persistence-verifier.ts to import the promoted helper instead of defining its own copy.
  • Add tests/unit/core/errors.errMessage.test.ts covering: Error instances, custom Error subclasses, string throws, structured-object throws (the issue Lossy error stringification in NametagMinter — [object Object] masks aggregator failure reason #191 reproducer), aggregator-shaped payloads, W40 redaction integration, arrays, null/undefined, BigInt unstringifiables, and cycle-safety.

Out of scope

The remaining ~89 occurrences of err instanceof Error ? err.message : String(err) in core/ and modules/ are deferred per the issue's "Optional follow-up" note — they surface in warn-logs / internal worker paths rather than user-facing errors. A bulk replacement would inflate this PR's scope.

Test plan

  • npx vitest run tests/unit/core/errors.errMessage.test.ts — 10/10 pass
  • npx vitest run tests/unit/payments/transfer/sphere-error-redaction.test.ts — 44/44 pass (no W40 regression)
  • npx vitest run tests/unit/modules/NametagMinter.test.ts tests/unit/payments/transfer/nostr-persistence-verifier.test.ts — 46/46 pass
  • npx vitest run tests/unit/core/ — 451/451 pass
  • npx vitest run tests/unit/payments/ tests/unit/modules/ — 3181/3181 pass
  • npm run typecheck — clean
  • npx eslint on the four changed files — clean
  • Manual verification against goggregator-test that an actual nametag-mint rejection surfaces a JSON payload (not [object Object]) — requires testnet access

Before / after

Before:

SphereError: Failed to mint nametag token: Submit failed: [object Object]

After (when aggregator returns a structured error):

SphereError: Failed to mint nametag token: Submit failed: {"status":"BAD_REQUEST","reason":"..."}

…er stringification

Operators saw `Submit failed: [object Object]` from `Sphere.init({ nametag })`
against the testnet aggregator because `NametagMinter` used the inline
`err instanceof Error ? err.message : String(err)` pattern, which collapses
non-Error throws (structured RPC payloads) to the default Object#toString
output. Issue #191 reports 35/35 e2e tests failing this way.

Promote the existing `errMessage` helper (previously local to
`modules/payments/transfer/nostr-persistence-verifier.ts`) to `core/errors.ts`
so it lives next to `redactCause` and is importable from any module.
`errMessage` routes unknown-shape errors through `redactCause` +
`JSON.stringify`, so the surfaced string carries field-level forensics
without leaking W40-redacted secret bytes.

Replace the two highest-visibility callsites in NametagMinter (the
submit-retry catch at :182 and the outer mintNametag catch at :256) with
`errMessage(error)`. The output for a rejected aggregator response now
reads e.g. `Submit failed: {"status":"BAD_REQUEST","reason":"..."}` —
immediately actionable.

The remaining ~89 occurrences of the lossy pattern in core/ and modules/
are intentionally left alone per the issue's "Optional follow-up" note —
they surface in warn-logs / internal worker paths rather than user-facing
errors and a bulk replacement would inflate this PR's scope.
@vrogojin vrogojin force-pushed the fix/issue-191-error-stringification branch from a570d94 to a2ac81d Compare June 8, 2026 08:35
@vrogojin vrogojin merged commit 23c20b1 into main Jun 8, 2026
3 checks passed
@vrogojin vrogojin deleted the fix/issue-191-error-stringification branch June 8, 2026 08:42
Sign up for free to 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.

Lossy error stringification in NametagMinter — [object Object] masks aggregator failure reason

1 participant