Skip to content

Standardize error handling with shared utility#434

Open
markvp wants to merge 4 commits intomatter-js:mainfrom
markvp:refactor/417-error-handling
Open

Standardize error handling with shared utility#434
markvp wants to merge 4 commits intomatter-js:mainfrom
markvp:refactor/417-error-handling

Conversation

@markvp
Copy link
Copy Markdown
Contributor

@markvp markvp commented Mar 24, 2026

Summary

  • Add getErrorMessage(err: unknown): string utility in packages/ws-controller/src/util/errorUtils.ts
  • Replace (err as Error).message pattern in WebSocketControllerHandler
  • Replace error instanceof Error ? error.message : String(error) pattern in ControllerCommandHandler and ChipConfigData
  • Export utility from @matter-server/ws-controller package

Test plan

  • npm run format passes
  • npm run lint passes
  • npm run build passes

Fixes #417

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings March 24, 2026 02:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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): string in ws-controller utilities.
  • Replaced ad-hoc error message extraction patterns with the shared utility in multiple handlers/converters.
  • Exported the utility from @matter-server/ws-controller for 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.

@markvp markvp requested a review from Copilot March 24, 2026 03:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

markvp and others added 4 commits March 24, 2026 17:03
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>
@markvp markvp force-pushed the refactor/417-error-handling branch from 4509fbc to 6b34bab Compare March 24, 2026 09:03
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.

Standardize error handling with shared utility

2 participants