Skip to content

refactor(error): add decentralized error category infrastructure#302

Merged
kcenon merged 1 commit into
mainfrom
refactor/issue-300-error-category-infrastructure
Jan 22, 2026
Merged

refactor(error): add decentralized error category infrastructure#302
kcenon merged 1 commit into
mainfrom
refactor/issue-300-error-category-infrastructure

Conversation

@kcenon

@kcenon kcenon commented Jan 22, 2026

Copy link
Copy Markdown
Owner

Summary

This PR implements Phase 1 of the decentralized error category system to improve system isolation and reduce coupling between components.

Key Changes

  • error_category: Abstract base class following std::error_category pattern for system-specific error categories
  • common_error_category: Singleton implementation for common/shared error codes (success, invalid_argument, not_found, timeout, etc.)
  • typed_error_code: Type-safe error code class that carries its category reference
  • Helper functions: make_typed_error_code(), is_success(), is_error() for convenient error code creation and checking
  • Result integration: error_info can now be constructed from typed_error_code for seamless integration

Design Decisions

  • Named typed_error_code to avoid conflict with existing using error_code = error_info; alias
  • Preserved backward compatibility with legacy error_code alias (marked deprecated)
  • Categories use thread-safe singleton pattern via C++11 static local initialization
  • Error codes carry both numeric value and category reference for clear origin identification

Architecture

error_category (abstract base)
    ├── common_error_category (singleton)
    │   └── codes: success, unknown_error, invalid_argument, not_found, ...
    └── [future] system-specific categories
        ├── network_error_category
        ├── database_error_category
        └── ...

typed_error_code
    ├── value(): int
    ├── category(): error_category&
    └── message(): string (from category)

Future Phases (not in this PR)

  • Phase 2: Migrate common errors to common_error_category
  • Phase 3: Create system-specific categories in dependent systems
  • Phase 4: Deprecate centralized error_codes.h

Test Plan

  • Unit tests for error_category base class functionality
  • Unit tests for common_error_category implementation
  • Unit tests for typed_error_code class with category support
  • Integration tests with Result<T>
  • Thread safety tests for singleton pattern
  • All 113 existing tests pass
  • Build succeeds on macOS with Clang

Closes #300

…se 1)

Implement the foundational infrastructure for the decentralized error
category system to improve system isolation and reduce coupling.

Key additions:
- error_category: Abstract base class following std::error_category pattern
- common_error_category: Singleton for common/shared error codes
- typed_error_code: Type-safe error code with category reference
- Helper functions: make_typed_error_code, is_success, is_error
- Integration with Result<T> via error_info constructor

Design decisions:
- Named typed_error_code to avoid conflict with existing error_code alias
- error_info now accepts typed_error_code for seamless integration
- Preserved backward compatibility with error_code = error_info alias
- Categories use singleton pattern with thread-safe initialization

This is Phase 1 of the decentralized error system. Future phases will:
- Migrate existing errors to common_error_category
- Create system-specific categories (network, database, etc.)
- Deprecate centralized error_codes.h

Closes #300
@kcenon kcenon merged commit aa542e0 into main Jan 22, 2026
24 checks passed
@kcenon kcenon deleted the refactor/issue-300-error-category-infrastructure branch January 22, 2026 12:35
kcenon added a commit that referenced this pull request Apr 13, 2026
…se 1) (#302)

Implement the foundational infrastructure for the decentralized error
category system to improve system isolation and reduce coupling.

Key additions:
- error_category: Abstract base class following std::error_category pattern
- common_error_category: Singleton for common/shared error codes
- typed_error_code: Type-safe error code with category reference
- Helper functions: make_typed_error_code, is_success, is_error
- Integration with Result<T> via error_info constructor

Design decisions:
- Named typed_error_code to avoid conflict with existing error_code alias
- error_info now accepts typed_error_code for seamless integration
- Preserved backward compatibility with error_code = error_info alias
- Categories use singleton pattern with thread-safe initialization

This is Phase 1 of the decentralized error system. Future phases will:
- Migrate existing errors to common_error_category
- Create system-specific categories (network, database, etc.)
- Deprecate centralized error_codes.h

Closes #300
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.

refactor: Decentralize error code registry to improve system isolation

1 participant