feat: implement typed error taxonomy and custom error classes (#18)#38
Open
TheDEV111 wants to merge 1 commit into
Open
feat: implement typed error taxonomy and custom error classes (#18)#38TheDEV111 wants to merge 1 commit into
TheDEV111 wants to merge 1 commit into
Conversation
|
@TheDEV111 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
The error hierarchy ( git fetch origin
git rebase origin/develop
git push --force-with-leaseKeep |
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 #18
📝 Overview & Summary
Currently, the SDK throws plain, generic
Errorinstances throughout its modules. This forces consumers to use brittle string-matching patterns intry/catchblocks to programmatically distinguish between specific error conditions (e.g. invalid meta-addresses, RPC failures, or view-tag mismatches).This PR resolves Issue #18 by implementing a granular, typed hierarchy of custom error classes under
src/errors.ts(re-exported from the SDK root entry point). These custom classes extend the native JavaScriptErrorclass (guaranteeing runtime backwards-compatibility) while carrying enumerable, structured metadata payloads, stable error codes, and dynamic documentation links.🛠️ Detailed Scope of Changes
1. The Error Hierarchy (
src/errors.ts)We have established a robust abstract taxonomy dividing errors into five primary functional domains:
2. Properties & Serialization Support
Every subclass instances includes:
name: Automatically matches the class name.code: A stable serializable constant string (e.g."WRAITH/INPUT/INVALID_SIGNATURE") to retain class identity across network boundaries.context: A structured object containing domain-specific parameters (e.g.statusCode,expectedLength,actualLength).docsLink: A direct link referencing the specific error details in the documentation guide.toJSON()onWraithErrorto ensure custom properties serialize cleanly withJSON.stringify(error).3. Codebase-wide Refactoring
throw new Error(...)calls with their typed equivalents.@throwscomments across public functions to document specific error behavior.4. Testing & QA
test/errors.test.ts): Added 17 unit tests verifyinginstanceofcorrectness (including ancestor matching likeWraithInputError), name/code/docsLink generation, property preservation, and serialization.InvalidSignatureErrorexceptions.5. Documentation
docs/errors.md): Wrote a complete, premium-quality developer guide containing the class tree, property mappings, stable codes reference table, and richtry/catchintegration examples.CHANGELOG.md): Noted the change in a new changelog file, warning developers about message string formatting adjustments.Errorinstances remain unaffected because all custom classes inherit fromError.error.message(e.g..toThrow('Expected 65-byte signature')) will break. Integrators must update their catch statements to use moderninstanceofchecking:✅ Verification & Testing Done
pnpm test, verifying that all 151 unit and E2E tests successfully pass.ESM dist/index.js 5.10 KB CJS dist/index.cjs 7.89 KB DTS dist/index.d.ts 8.62 KB ⚡️ Build success in 582ms