You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Meanwhile contracts/shared/src/errors.rs defines a rich, ~120-variant KoraError enum (e.g. ProtocolPaused, InsufficientFunds, ExceedsFundingTarget, TokenNotWhitelisted, FundingDeadlinePassed, etc.) that every contract returns as structured Result<_, KoraError>
failures. There is no TypeScript representation of this enum anywhere in sdk/, and no logic
that parses the numeric error code out of a Soroban contract-failure XDR/simulation error and
maps it back to a named variant. Every SDK consumer is left parsing ad-hoc stringified error
payloads to guess what actually went wrong.
Requirements and Context
This is a genuine cross-language integration gap between the Rust error taxonomy (the
authoritative source of truth) and the TypeScript client that's supposed to let external
consumers build against the protocol. Note this is different in kind from the documentation-only docs/ERRORS.md gap (open issue #279) — this issue is about a programmatic, typed decoding
layer in the SDK itself, not documentation.
Suggested Execution
git checkout -b feature/sdk-kora-error-decoding
Generate (or hand-maintain, with a comment cross-referencing the source of truth) a
TypeScript enum KoraError { Unauthorized = 1, NotAdmin = 2, ... } in sdk/src/errors.ts
mirroring contracts/shared/src/errors.rs exactly, including the numeric discriminants.
Add a decodeContractError(raw: unknown): KoraError | undefined helper that extracts the
numeric error code from a Soroban simulation/transaction failure payload (the Error(#N)
contract-error convention) and resolves it to the enum.
Update BaseClient.invoke() to throw a typed KoraContractError (carrying both the decoded KoraError variant, when resolvable, and the raw payload as a fallback) instead of a bare Error.
Add tests (per issue Add Tests for Invoice NFT Contracts #11) using representative captured simulation-failure payloads for a
handful of variants (e.g. ProtocolPaused, InsufficientFunds) proving correct decoding.
Description
sdk/src/base.ts'sinvoke()method surfaces failures as raw, unstructured strings:Meanwhile
contracts/shared/src/errors.rsdefines a rich, ~120-variantKoraErrorenum (e.g.ProtocolPaused,InsufficientFunds,ExceedsFundingTarget,TokenNotWhitelisted,FundingDeadlinePassed, etc.) that every contract returns as structuredResult<_, KoraError>failures. There is no TypeScript representation of this enum anywhere in
sdk/, and no logicthat parses the numeric error code out of a Soroban contract-failure XDR/simulation error and
maps it back to a named variant. Every SDK consumer is left parsing ad-hoc stringified error
payloads to guess what actually went wrong.
Requirements and Context
This is a genuine cross-language integration gap between the Rust error taxonomy (the
authoritative source of truth) and the TypeScript client that's supposed to let external
consumers build against the protocol. Note this is different in kind from the documentation-only
docs/ERRORS.mdgap (open issue #279) — this issue is about a programmatic, typed decodinglayer in the SDK itself, not documentation.
Suggested Execution
git checkout -b feature/sdk-kora-error-decodingTypeScript
enum KoraError { Unauthorized = 1, NotAdmin = 2, ... }insdk/src/errors.tsmirroring
contracts/shared/src/errors.rsexactly, including the numeric discriminants.decodeContractError(raw: unknown): KoraError | undefinedhelper that extracts thenumeric error code from a Soroban simulation/transaction failure payload (the
Error(#N)contract-error convention) and resolves it to the enum.
BaseClient.invoke()to throw a typedKoraContractError(carrying both the decodedKoraErrorvariant, when resolvable, and the raw payload as a fallback) instead of a bareError.handful of variants (e.g.
ProtocolPaused,InsufficientFunds) proving correct decoding.docs/ERRORS.md(issue Implementdocs/ERRORS.mdmapping everyKoraErrorvariant to cause and recommended handling #279, if/when completed) to keep the two in sync, butdo not block this issue on that doc existing.
Acceptance Criteria
sdk/contains aKoraErrorenum whose variants and numeric values exactly matchcontracts/shared/src/errors.rsBaseClient.invoke()throws a typed error exposing the decodedKoraErrorvariant when the failure payload contains a recognizable contract error codeGuidelines: PR description must include
Closes #<issue-number>.Complexity: High (200 points)