feat: add typed SdkErrorCode enum and SdkError class (#607) - #632
Merged
Kingsman-99 merged 1 commit intoAug 26, 2026
Merged
Conversation
Consumers previously had to string-match error messages to distinguish failure cases. Add an SdkErrorCode enum and SdkError class (extends Error, carries code + optional details) so callers can switch on err.code instead. Export both plus an isSdkError type guard from src/index.ts. Note: src/errors.ts already used typed StellarSplitError subclasses throughout (no plain `throw new Error(...)` calls existed), so there was nothing to migrate for that acceptance criterion.
6 tasks
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.
Title:
feat: add typed SdkErrorCode enum and SdkError class (#607)
Body:
Summary
Closes #607.
src/errors.tsconsumers previously had no reliable way to switch on errortype — they had to string-match
.message, which breaks whenever thewording changes. This adds a typed error code so callers can branch on
err.codeinstead.SdkErrorCodeenum tosrc/errors.tswithINVOICE_NOT_FOUND,INSUFFICIENT_FUNDS,DEADLINE_EXPIRED,INVALID_RECIPIENT,SdkErrorclass extendingErrorwithcode: SdkErrorCodeanddetails?: unknownisSdkError(e: unknown): e is SdkErrortype guardSdkError,SdkErrorCode, andisSdkErrorfromsrc/index.tsNote on the "replace
throw new Error(...)" acceptance criterion:src/errors.tsalready threw only typedStellarSplitErrorsubclasseseverywhere — there were no plain
throw new Error(...)calls in the file tomigrate, so this criterion is satisfied with no changes needed there.
Test plan
test/sdkError.test.tscovering:isSdkErrortrue/false cases,SdkErrorcarries the correctcode, existing behavior (message,details, instanceof
Error) preservednpx vitest run test/sdkError.test.ts test/errorSuggestions.test.ts test/horizonErrorClassifier.test.ts— all 50 tests passtsc --noEmitshows thesame 217 pre-existing errors on
main, none touchingerrors.tsorindex.ts's new exports)