feat(errors): add cause chaining, 6 typed error classes, and toJSON#83
Merged
Conversation
Pass { cause: err } in mapGrpcError so the original gRPC ServiceError
is preserved in the error chain for logging and debugging.
Add ResourceExhaustedError, DataLossError, OutOfRangeError,
CancelledError, UnimplementedError, and DeadlineExceededError, wiring
each into STATUS_MAP and exporting from src/index.ts.
Add toJSON() on DecreeError so logging frameworks retain name, code,
and message as structured fields on every error subclass.
Expand test/errors.test.ts to cover new typed classes, cause chaining,
and toJSON behavior.
Co-Authored-By: Claude <noreply@anthropic.com>
Closes #52
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Summary
ServiceErrorvia{ cause: err }inmapGrpcError, so stack traces and metadata aren't silently dropped.ResourceExhaustedError,DataLossError,OutOfRangeError,CancelledError,UnimplementedError,DeadlineExceededError) and wires them into the status map and public index.toJSON()onDecreeErrorso structured loggers (Pino, Winston, etc.) includename,code, andmessagewithout custom serializers.Test plan
mapGrpcError(grpcErr).cause === grpcErrfor both typed and generic pathstoJSON()tests: correct fields on base class and subclassestsc --noEmitcleanCloses #52