Skip to content

Design a shared error hierarchy for aggregator and component gems #26

Description

@coderabbitai

Summary

Redesign the shared error hierarchy for the CNPJ utility gems so the aggregator-level contract sits at the top of the hierarchy and errors raised by component gems participate as leaf errors beneath that shared contract.

Rationale

cnpj-utilities currently aggregates cnpj-fmt, cnpj-gen, and cnpj-val, whose errors propagate unchanged. This prevents consumers of the aggregator from reliably rescuing one unified domain error family while retaining native error specificity.

The redesign likely requires a separate shared error-contract package (or equivalent dependency-neutral abstraction) so component gems can depend on the common hierarchy without depending on the aggregator itself. Because this changes public exception ancestry and inverts dependencies, it is a breaking change and should be planned for a later major release.

Affected areas

  • packages/cnpj-utilities — façade documentation and aggregator-facing error contract
  • packages/cnpj-fmt — formatter errors
  • packages/cnpj-gen — generator errors
  • packages/cnpj-val — validator errors
  • Any related CPF packages if a shared Brazilian-document error contract is selected

Required changes

  1. Decide and document the ownership and package location of the shared error contract.
  2. Define a domain root error and marker/module strategy that remains compatible with Ruby native error classes (all library errors must remain descendants of StandardError).
  3. Update component error classes so they inherit from or otherwise participate in the shared contract without introducing a dependency from leaves to the aggregator.
  4. Define a migration and versioning plan for consumers rescuing existing component-specific errors.
  5. Update public documentation and tests to show the full inheritance chains, marker inclusion, precise trigger conditions, and rescue granularity.

Acceptance criteria

  • A dependency-neutral architecture is selected and documented.
  • Component errors can be rescued both at their native/component-specific granularity and through a unified domain-level contract.
  • No component package depends on the top-level aggregator package.
  • Public errors descend from StandardError; neither direct inheritance from nor rescue of Exception is introduced.
  • Compatibility impact, deprecations, and target major-version releases are documented.
  • Tests and package READMEs cover the new hierarchy and rescue behavior.

Context

Requested by @juliolmuller during review of #25.

Metadata

Metadata

Assignees

Labels

enhancementNew minor or major features.refactoringNon-functional improvements or changes.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions