Skip to content

Integrate DetailedError.forUnexpectedSwitchDefault() from ts-npm-packages PR #63 #681

Description

@coderabbitai

Summary

Integrate the changes introduced in couimet/ts-npm-packages#63 into RangeLink, which adds a static forUnexpectedSwitchDefault() factory method to the DetailedError base class in the @couimet/detailed-error package.

Rationale

The new factory method standardizes error creation for unexpected switch/default cases across subclasses of DetailedError, reducing boilerplate and improving consistency in error messaging (Unexpected <label>: <JSON.stringify(value)>), while still allowing a code override for subclasses using standalone enums.

Required Changes

  • Bump the @couimet/detailed-error dependency (and @couimet/detailed-error-testing if used) in RangeLink to the version that includes PR [Phase 5.2] Regex escaping contracts #63.
  • Identify existing switch/default blocks in RangeLink that currently throw ad-hoc DetailedError instances (or UNEXPECTED_CODE_PATH equivalents) and replace them with calls to DetailedError.forUnexpectedSwitchDefault(...).
  • If RangeLink's test suite asserts on DetailedError instances, consider adopting the toBeDetailedError matcher from @couimet/detailed-error-testing for more readable assertions, mirroring the conversion done in PR [Phase 5.2] Regex escaping contracts #63.
  • Verify moduleNameMapper / Jest config changes are not needed on RangeLink's side (PR [Phase 5.2] Regex escaping contracts #63 required this in ts-npm-packages to keep a single DetailedError module instance during tests).

Affected Areas

  • RangeLink modules/files using DetailedError for unexpected switch/default handling
  • Jest configuration (if @couimet/detailed-error-testing is adopted)
  • package.json dependency versions

Acceptance Criteria

  • @couimet/detailed-error dependency updated to the version containing forUnexpectedSwitchDefault()
  • Existing unexpected switch/default error paths in RangeLink refactored to use DetailedError.forUnexpectedSwitchDefault()
  • Tests updated/passing, optionally using the toBeDetailedError matcher
  • No regressions in existing instanceof Error / instanceof DetailedError behavior

References

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions