Repository navigation
Add contract error parsing and typed batch payload definitions - #1021
Merged
Jaydbrown merged 1 commit intoOct 20, 2026
Conversation
closes conduit-protocol#913 closes conduit-protocol#915 Soroban host errors surface as raw integers (e.g. `Error(Contract, #12)`), which makes them hard to diagnose. - `parseContractError(error, contract?, context?)` extracts the numeric contract error code from an unknown value (host-error message, `{ code }` object, or `cause` chain) and maps it to the matching typed error class. - Error numbers are contract-scoped, so the contract argument selects the catalogue to read. When it is omitted the code is only auto-resolved if exactly one contract defines it; otherwise a `ContractError` lists the candidates instead of guessing the wrong meaning. - Richer stream errors (`StreamNotFoundError`, `UnauthorizedStreamActionError`, `InvalidStreamStateError`) are built when the caller supplies the matching context; otherwise a `ConduitError` with the correct contract-scoped message is returned. - Errors without a contract error code are returned unchanged, so the helper is safe to call directly in a catch block. Batch operations now have dedicated payload types: - `BatchStreamCreationPayload` requires `recipient`, `token` and `depositAmount`, so a missing recipient or a misformatted amount is caught at compile time. - `BatchWithdrawPayload` requires `streamId`. - `StreamsModule.createBatchStreams()` and `StreamsModule.batchWithdraw()` use the new payload types; the existing `StreamConfig` and `BatchWithdrawItem` names remain as compatible aliases.
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.
closes #913
closes #915
Summary
Two related TypeScript improvements to the SDK.
1.
parseContractError— contract error codes → typed errors (#913)Soroban host errors surface as raw integers (e.g.
Error(Contract, #12)), socallers get no actionable message and cannot branch on the failure reason.
parseContractError(error, contract?, context?)extracts the numeric contracterror code from an unknown value and maps it to the matching typed error class:
stream#11ClawbackDisabledClawbackNotEnabledErrorstream#1NotAuthorizedUnauthorizedStreamActionError(withoperation+caller)stream#2StreamNotFoundStreamNotFoundError(withstreamId)streamlifecycle codesInvalidStreamStateError(withoperation)factory#8 / #9 / #6RateExceedsMaxError/DurationTooShortError/BackdatedStreamErrorgovernor#2InvalidParamGovernorInvalidParamErrorConduitErrorwith the contract-scoped messageDesign notes:
things on the stream, factory and governor contracts, so the
contractargument selects the catalogue to read. When it is omitted the code is
auto-resolved only if exactly one contract defines it; otherwise a
ContractErrorlists the candidates rather than reporting the wrong meaning.operation and a caller that cannot be recovered from the numeric code. They
are only built when the caller supplies that context; otherwise a
ConduitErrorwith the correct message is returned.failures, timeouts, user cancellations) are returned unchanged.
2. Typed batch payloads (#915)
Batch operations accepted loosely-shaped objects. Two dedicated payload types
now make the required fields explicit:
BatchStreamCreationPayload— requiresrecipient,tokenanddepositAmount, so a missing recipient or a misformatted amount is acompile-time error.
BatchWithdrawPayload— requiresstreamId.StreamsModule.createBatchStreams()andStreamsModule.batchWithdraw()usethe new types. The existing
StreamConfigandBatchWithdrawItemnames stayas compatible aliases, so this is not a breaking change.
Verification
npx tsc --noEmit— no new type errors (the 12 pre-existing errors inclient.ts/custom-fetch.ts/soroban.tsare unchanged frommain).npx vitest run— 18 new tests added (14 forparseContractError, 4 forthe payload types), all passing. The 17 failing tests in
custom-fetch*/relayer-stress/soroban-retry-after/streams.test.tsfail identically onmainand are unrelated to thischange.