Skip to content

Don't treat Object.prototype keys as known backend error codes - #329

Open
Dusk1e wants to merge 1 commit into
FhenixProtocol:masterfrom
Dusk1e:fix/api-error-own-property
Open

Don't treat Object.prototype keys as known backend error codes#329
Dusk1e wants to merge 1 commit into
FhenixProtocol:masterfrom
Dusk1e:fix/api-error-own-property

Conversation

@Dusk1e

@Dusk1e Dusk1e commented Aug 18, 2026

Copy link
Copy Markdown

isBackendApiErrorCode checks value in BACKEND_ERROR_CODE_TO_COFHE_ERROR_CODE, and in also matches inherited keys. So a backend error of toString, constructor, valueOf or hasOwnProperty counts as recognised, and mapApiErrorCodeToCofheErrorCode returns the inherited value, a function, instead of the fallback its own doc comment promises. CofheError.code then holds a non-string, so err.code === CofheErrorCode.X quietly stops matching.

The value is taken verbatim from record.error in the response body, and the mapper runs in the decrypt and sealoutput error paths through submitRetry, tnDecryptV2 and tnSealOutputV2, so it is reachable from whatever the endpoint returns.

Switched to an own-property check. Added a case to the existing fallback tests in apiError.test.ts; it fails on master with Received [Function toString] and passes after. Full node suite is 377 passing, and the two failing files are the pre-existing @cofhe/test-setup resolution errors that also fail on master. tsc reports the same three errors before and after, all from that same missing module.

isBackendApiErrorCode used `value in BACKEND_ERROR_CODE_TO_COFHE_ERROR_CODE`,
and `in` also matches inherited keys. A backend `error` of toString,
constructor, valueOf or hasOwnProperty was therefore treated as recognised, and
mapApiErrorCodeToCofheErrorCode returned the inherited value, a function,
instead of the fallback its docs promise. CofheError.code then held a non-string,
so err.code === CofheErrorCode.X comparisons silently failed.

The value comes straight from record.error in the response body, and the mapper
runs in the decrypt and sealoutput error paths via submitRetry, tnDecryptV2 and
tnSealOutputV2.

Switched to an own-property check and added a case to the existing fallback
tests. Recognised codes and ordinary unknown codes are unaffected.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@changeset-bot

changeset-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3d5d9d3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@cofhe/sdk Patch
@cofhe/abi Patch
@cofhe/hardhat-3-plugin Patch
@cofhe/hardhat-plugin Patch
@cofhe/mock-contracts Patch
@cofhe/react Patch
@cofhe/site Patch
@cofhe/example-react Patch
@cofhe/foundry-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Aug 18, 2026

Copy link
Copy Markdown

@Dusk1e is attempting to deploy a commit to the Fhenix Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant