Skip to content

refactor(ts-client): replace string literal errors with SdkErrorCode enum#270

Open
Shawnchee wants to merge 3 commits intoMeteoraAg:mainfrom
Shawnchee:refactor/dlmm-sdk-error-enum
Open

refactor(ts-client): replace string literal errors with SdkErrorCode enum#270
Shawnchee wants to merge 3 commits intoMeteoraAg:mainfrom
Shawnchee:refactor/dlmm-sdk-error-enum

Conversation

@Shawnchee
Copy link

Summary

Replaces the ErrorName string literal union with an SdkErrorCode enum
for SDK-side errors, centralises default error messages, and adds a
type-safe DlmmSdkError.is() helper for catch blocks

Problem

  • Error names are raw strings and every throw site must hardcode a message
  • No type-safe way to check error types in catch blocks

Changes

ts-client/src/dlmm/error.ts

  • Added SdkErrorCode enum with existing error names
  • Added SDK_ERROR_MESSAGES map with default messages
  • Updated DlmmSdkError constructor: errorMessage is now optional,
    falls back to SDK_ERROR_MESSAGES
  • Added DlmmSdkError.is() static type predicate

ts-client/src/dlmm/index.ts

  • Updated 5 throw sites to use SdkErrorCode enum
  • Removed unused imports: getSimulationComputeUnits,
    ComputeBudgetInstruction

ts-client/src/test/sdk_error.test.ts (newly added)

  • 8 unit tests covering constructor, default/custom messages,
    and static is() method

Breaking Changes

None. Enum values match the original string literals. Existing
error handling code continues to work

Testing

cd ts-client
npx jest src/test/sdk_error.test.ts 

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.

1 participant