Skip to content

refactors and hardens the MessageFactory#39

Merged
Rashed99Azm merged 1 commit into
developfrom
feat/refactor-error-codes
Jun 1, 2026
Merged

refactors and hardens the MessageFactory#39
Rashed99Azm merged 1 commit into
developfrom
feat/refactor-error-codes

Conversation

@Rashed99Azm
Copy link
Copy Markdown
Collaborator

Summary

This PR refactors and hardens the MessageFactory pipeline to improve reliability, observability, and localization integrity while removing the legacy Errors infrastructure.

Changes

Localization Integrity Validation

  • Added SystemCodeMapIntegrityTests to validate:
    • Every SystemCodeMap key has both Arabic and English translations.
    • No duplicate system codes exist.
    • Every SystemCode constant value matches its field name.
  • Linked Resources.yaml into Application.Tests output to ensure YamlLocalizationStore can resolve translations during test execution.

Improved Observability

  • Injected ILogger<MessageFactory> into MessageFactory.
  • Added warning logs when:
    • ResolveCode() falls back to ERR900 due to an unmapped key.
    • Localize() returns the original key because a translation is missing.
  • Standardized all six MessageFactory entry points to use the shared resolution and localization pipeline.

Legacy Errors System Removal

  • Removed CCE.Application.Common.Errors.
  • Removed the related DI registration.
  • Confirmed no remaining runtime injection or usage sites.
  • Deleted 44 obsolete localization keys, including legacy:
    • IDENTITY_*
    • CONTENT_*
    • COMMUNITY_*
    • COUNTRY_COUNTRY_*
    • GENERAL_*
    • NOTIFICATIONS_*
    • VALIDATION_*

Bug Fixes

Fixed three cases that silently fell back to ERR900:

Key | Code -- | -- COUNTRY_CODE_NOT_FOUND | ERR130 LOOKUP_CREATED | CON070 LOOKUP_UPDATED | CON071

Added the missing entries to both SystemCode and SystemCodeMap.

Translation Coverage

  • Added approximately 60 missing Arabic and English translations.
  • Ensured every SystemCodeMap entry resolves successfully from Resources.yaml.
  • Future regressions are prevented by the new integrity test suite.

ApplicationErrors Standardization

Added new domain groups:

  • PlatformSettings
  • Media
  • Verification
  • Lookups

Refactored all 35 MessageFactory convenience methods to use ApplicationErrors.* constants, eliminating remaining hardcoded string literals.

Result

  • No silent localization failures.
  • No silent code-to-error fallbacks.
  • Full translation coverage for all mapped system codes.
  • Improved diagnostics through structured logging.
  • Removal of unused legacy error infrastructure.
  • Centralized and strongly-typed error key management.

…move legacy Errors system

  Phase 1 — integrity test: add SystemCodeMapIntegrityTests asserting every
  SystemCodeMap domain key has ar+en translations, no duplicate codes, and
  every SystemCode constant value matches its field name. Link Resources.yaml
  into Application.Tests output so YamlLocalizationStore finds it at test time.

  Phase 2 — observable fallbacks: inject ILogger<MessageFactory>; ResolveCode()
  logs Warning when a key falls back to ERR900, Localize() logs Warning when
  GetString returns the raw key unchanged. All 6 entry points route through
  these helpers.

  Phase 4 — legacy removal:
  - Delete CCE.Application.Common.Errors and its DI registration (no live
    injection sites); 44 prefixed legacy yaml keys removed (IDENTITY_*,
    CONTENT_*-prefixed, COMMUNITY_*, COUNTRY_COUNTRY_*, GENERAL_*,
    NOTIFICATIONS_*-prefixed, VALIDATION_*-prefixed duplicates).
  - Fix 3 silent ERR900 bugs: add COUNTRY_CODE_NOT_FOUND (ERR130),
    LOOKUP_CREATED (CON070), LOOKUP_UPDATED (CON071) to SystemCode +
    SystemCodeMap.
  - Add ~60 missing ar+en translations so every SystemCodeMap key resolves
    in Resources.yaml (integrity test enforces this going forward).
  - Extend ApplicationErrors with PlatformSettings, Media, Verification,
    Lookups domain classes; standardize all 35 MessageFactory convenience
    shortcuts to ApplicationErrors.* constants — zero bare string literals.
@Rashed99Azm Rashed99Azm merged commit b3aab56 into develop Jun 1, 2026
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.

2 participants