17 — Error Handling Standards

Status: Ratified Version: 1.0.0 Applies to: All layers; exception taxonomy; retries; rollback; graceful degradation; recovery


1. Philosophy

HunterX treats failures as first-class, observable, and recoverable events. Errors are never silent, never swallowed, and never leave the system in an unknown state. The platform fails loud but degrades gracefully.


2. Exception Taxonomy

Root: HunterXError. Hierarchy:

HunterXError
├── ConfigurationError        (bad config/manifest/schema)
├── ScopeViolationError       (HX-SCOPE-*)        [non-retryable, critical]
├── ValidationError           (HX-VALID-*)        [non-retryable]
├── NotFoundError             (HX-NF-*)           [non-retryable]
├── AuthenticationError / AuthorizationError      [non-retryable]
├── TransientError            (HX-TRANS-*)        [retryable]
│   ├── NetworkError
│   ├── TimeoutError
│   ├── RateLimitedError
│   ├── ProviderUnavailableError
│   └── ToolCrashedError
├── PermanentError            (HX-PERM-*)         [non-retryable]
│   ├── ToolMissingError
│   ├── UnsupportedModeError
│   ├── ParseError
│   └── DataIntegrityError
└── CancelledError            (HX-CANCEL-*)       [no retry]

Rules:


3. Error Codes

Format: HX-<AREA>-<NNN>. Areas: SCOPE, VALD, TRANS, PERM, AUTH, CFG, PLUGIN, TOOL, DB, AI, QUEUE, CANCEL.

Codes are registered in docs/bible/README.md error-code table (or linked register) and are stable across releases (new codes added; never reused).

Example:

Code Meaning Retryable
HX-SCOPE-001 Target outside engagement scope no
HX-TRANS-001 Transient network failure yes
HX-TRANS-002 Tool timed out yes (bounded)
HX-PERM-001 Tool binary missing no
HX-AI-001 AI output failed schema validation yes (bounded)
HX-DB-001 Store unavailable yes (bounded)
HX-PLUGIN-001 Plugin load failure no

4. Failure Handling by Layer

Layer Behavior
Domain Raise typed domain errors; never I/O errors leak in
Application Map use-case outcomes; do not leak stack traces to delivery
CLI Print code, safe message, and remediation hint; exit code per table
API JSON error envelope (20 §Errors)
Worker/Engine Step-level retry → degrade → pause → fail (per 10 §7)
Adapter Translate tool failures to typed outcomes (06 §13)

5. Retry Policy

Policy Default
Transient network 3 attempts
Tool timeout 2 attempts
Rate limited up to policy, honor Retry-After
AI schema failure 2 attempts then fallback
DB unavailable 3 attempts then degrade
Scope violation never retried; abort + alert

6. Rollback


7. Graceful Degradation

Degradation ladder (applied in order, recorded in events/logs):

  1. Fallback: use alternate provider/tool/strategy (AI → rule-based; provider A → B; tool X → Y with same capability).
  2. Route around: mark tool unavailable; continue with peers; skip with reason.
  3. Scope reduction: execute reduced-profile (fast over thorough).
  4. Pause for operator: stop and request intervention (approval gate).
  5. Fail the unit, preserve the mission: isolate failed step; mission may complete-with-warnings.

Degradation is observable: degradation.activated event with reason and level; metrics hx_degradation_activations_total.


8. Recovery & Resume


9. Operator-Facing Errors


10. Testing Error Paths


11. References