Skip to content

fix(sdk): align contract error enums with on-chain errors.rs - #6

Merged
K1NGD4VID merged 2 commits into
mainfrom
fix/sdk-contract-error-enums
Sep 15, 2026
Merged

K1NGD4VID merged 2 commits into
mainfrom
fix/sdk-contract-error-enums

Conversation

@fadesany

Copy link
Copy Markdown
Contributor

Summary

TreasuryError and FactoryError in packages/sdk/src/types.ts had drifted from the contracts, so most contract failures showed the wrong message. For example, treasury #7 (RequestNotPending) showed the budget-cap text.

1. Realign both enums with the contract source (e3c5bde)

  • Mirrors charter-contract@be72224 exactly: contracts/treasury/src/errors.rs L10-20 (11 errors) and contracts/factory/src/errors.rs L7-13 (4 errors).
  • Rewrites both message tables. Messages cover the places where the contract reuses a code: RequestNotPending also fires for a missing request, and InvalidAmount also fires for a missing category or a cap below spent.
  • Removes the "known drift" notes from docs/developer-guide/sdk-reference.md and docs/smart-contracts/treasury.md. The docs' error tables already matched the source.

2. Add FactoryError.TreasuryInitFailed = 5 (f87f960)

  • Matches the contract-side change that wraps any failure of the new treasury's initialize in a factory error, so treasury codes can't collide with factory codes 1–4.
  • The contract reverts the whole deploy, so the message says no organization was created.

Why this is safe

  • @charter/sdk is private (0.1.0) and only this monorepo uses it.
  • Nothing outside types.ts imports TreasuryError / FactoryError or reads .code. The web app only reads .message off TreasuryCallError / FactoryCallError, and the indexer is Go.

Testing

Not covered

  • AlreadyApproved (#9) wasn't tested live: no testnet request has an approval yet, so it needs one real signed approval first.
  • TreasuryInitFailed (Feat/dashboard redesign #5) can't be triggered on testnet yet. That contract change isn't committed or deployed in charter-contract. This PR only adds a code, so it's safe to merge before then.
  • The new-org form validates the threshold before submitting, so Feat/dashboard redesign #5 won't show up during normal form use. It would only come from other failures inside initialize.

🤖 Generated with Claude Code

TreasuryError and FactoryError had drifted from the contracts, so most
contract failures showed the wrong message (e.g. treasury #7
RequestNotPending rendered the budget-cap text).

Mirror charter-contract@be72224 exactly:
- contracts/treasury/src/errors.rs L10-20 (11 variants)
- contracts/factory/src/errors.rs L7-13 (4 variants)

Rewrite both message tables, covering the overloaded raise sites
(RequestNotPending for missing requests, InvalidAmount for missing
categories / cap below spent). Drop the known-drift doc notes; the
contract docs tables already matched the source.
The factory contract now wraps any failure of the new treasury's
initialize in its own TreasuryInitFailed = 5 instead of letting
treasury codes (which collide with factory codes 1-4) leak through.

Mirror charter-contract contracts/factory/src/errors.rs L16 and add a
message. The contract reverts the whole deploy (org count stays 0), so
the message says no organization was created.
@vercel

vercel Bot commented Sep 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
app-web Ready Ready Preview Sep 15, 2026 7:33pm UTC

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.

2 participants