fix(sdk): align contract error enums with on-chain errors.rs - #6
Merged
Merged
Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This was referenced Sep 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TreasuryErrorandFactoryErrorinpackages/sdk/src/types.tshad 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)charter-contract@be72224exactly:contracts/treasury/src/errors.rsL10-20 (11 errors) andcontracts/factory/src/errors.rsL7-13 (4 errors).RequestNotPendingalso fires for a missing request, andInvalidAmountalso fires for a missing category or a cap below spent.docs/developer-guide/sdk-reference.mdanddocs/smart-contracts/treasury.md. The docs' error tables already matched the source.2. Add
FactoryError.TreasuryInitFailed = 5(f87f960)initializein a factory error, so treasury codes can't collide with factory codes 1–4.Why this is safe
@charter/sdkis private (0.1.0) and only this monorepo uses it.types.tsimportsTreasuryError/FactoryErroror reads.code. The web app only reads.messageoffTreasuryCallError/FactoryCallError, and the indexer is Go.Testing
npm run typecheckpasses for@charter/sdkand@charter/web.get_request/cancel_requeston a non-pending request → fix(sdk): call deploy_treasury with contract arg order and org-id return #7,get_category→ #11, factoryget_org→ feat: public marketing landing page at / #4, approve by a non-approver → feat: public marketing landing page at / #4, cancel by a non-requester → #10. All passed.factoryErrorMessage(5)returns the new message instead of the "(code 5)" fallback.cargo test -p charter-factorypasses 13/13, including the newTreasuryInitFailedtests.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 incharter-contract. This PR only adds a code, so it's safe to merge before then.initialize.🤖 Generated with Claude Code