Standardize error handling with shared utility#434
Open
markvp wants to merge 4 commits intomatter-js:mainfrom
Open
Standardize error handling with shared utility#434markvp wants to merge 4 commits intomatter-js:mainfrom
markvp wants to merge 4 commits intomatter-js:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Standardizes extraction of human-readable error messages across packages by introducing and reusing a shared getErrorMessage(err: unknown) utility.
Changes:
- Added
getErrorMessage(err: unknown): stringinws-controllerutilities. - Replaced ad-hoc error message extraction patterns with the shared utility in multiple handlers/converters.
- Exported the utility from
@matter-server/ws-controllerfor cross-package consumption.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/ws-controller/src/util/errorUtils.ts | Adds shared error-to-message utility. |
| packages/ws-controller/src/server/WebSocketControllerHandler.ts | Uses shared utility for WebSocket error response details. |
| packages/ws-controller/src/index.ts | Exports the new utility from the package public API. |
| packages/ws-controller/src/controller/ControllerCommandHandler.ts | Uses shared utility when building commissioning failure messages. |
| packages/matter-server/src/converter/ChipConfigData.ts | Uses shared utility when formatting certificate verification failures. |
Replace three different error message extraction patterns with a shared getErrorMessage(err: unknown) utility function. Fixes matter-js#417 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ndling Handle string errors directly, detect Error-like objects with message property, improving diagnosability for non-standard error values. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…erialization Improve getErrorMessage to handle Error-like objects with non-string message properties, nested Error instances, and fall back to JSON serialization for plain objects to avoid unhelpful [object Object]. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Cover all branches: string errors, Error instances/subclasses, Error-like objects, nested Error messages, JSON serialization fallback, circular objects, and primitive types. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
4509fbc to
6b34bab
Compare
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
getErrorMessage(err: unknown): stringutility inpackages/ws-controller/src/util/errorUtils.ts(err as Error).messagepattern in WebSocketControllerHandlererror instanceof Error ? error.message : String(error)pattern in ControllerCommandHandler and ChipConfigData@matter-server/ws-controllerpackageTest plan
npm run formatpassesnpm run lintpassesnpm run buildpassesFixes #417
🤖 Generated with Claude Code