Skip to main content

palisade_errors/
definitions.rs

1//! Pre-defined error codes for the deception agent.
2//!
3//! # Taxonomy & Governance
4//!
5//! This file defines the specific error instances used across the system.
6//! It is structured to support **adversarial resilience**, separating
7//! internal system failures from deception-specific narrative failures.
8//!
9//! # Severity & Impact
10//!
11//! Unlike standard systems, errors here include an `ImpactScore` rating
12//! that maps to an `ErrorImpact` level. A `DCP_NARRATIVE_BREAK` is not a log event;
13//! it is an operational alert requiring immediate persona contingency.
14//!
15//! Impact scores are assigned based on heuristics similar to the previous
16//! version's scoring system, mapped to the new 0-1000 scale:
17//! - Noise (0-50) | internal noise, no impact
18//! - Flaw (51-150) | Minor discrepancy
19//! - Jitter (151-300) | Performance issues
20//! - Glitch (301-450) | Functional error
21//! - Suspicion (451-600) | Logic inconsistency
22//! - Leak (601-750) | Information disclosure
23//! - Collapse (751-850) | Total failure of emulation
24//! - Escalation (851-950) | Unintended access
25//! - **Breach** (951-1000) | Sandbox breakout risk
26//!
27//! Scores respect namespace authority (e.g., no Breach-level in non-authorized namespaces).
28//! Maximum impact caps per namespace are now documented and should be enforced in future macro updates:
29//! - CORE: max 850
30//! - CFG: max 300
31//! - DCP: max 1000 (authorized for Breach)
32//! - TEL: max 600
33//! - COR: max 600
34//! - RSP: max 600
35//! - LOG: max 300
36//! - PLT: max 500
37//! - IO: max 300
38//!
39//! # Governance
40//!
41//! Numeric ranges are strictly enforced via the `tests` module at the bottom
42//! of this file. Ad-hoc definition of codes outside their namespace range
43//! will fail the build.
44//!
45//! To strengthen governance:
46//! - Range enforcement should be promoted to the macro level in codes.rs for compile-time checks.
47//! - Escalation comments standardize response protocols.
48
49use crate::{define_error_codes, namespaces, OperationCategory};
50
51/// Error code range constants for maintaining namespace boundaries.
52/// Checked for consistency in `tests` module.
53pub mod ranges {
54    pub const CORE_START: u16 = 1;   pub const CORE_END: u16 = 99;
55    pub const CFG_START:  u16 = 100; pub const CFG_END:  u16 = 199;
56    pub const DCP_START:  u16 = 200; pub const DCP_END:  u16 = 299;
57    pub const TEL_START:  u16 = 300; pub const TEL_END:  u16 = 399;
58    pub const COR_START:  u16 = 400; pub const COR_END:  u16 = 499;
59    pub const RSP_START:  u16 = 500; pub const RSP_END:  u16 = 599;
60    pub const LOG_START:  u16 = 600; pub const LOG_END:  u16 = 699;
61    pub const PLT_START:  u16 = 700; pub const PLT_END:  u16 = 799;
62    pub const IO_START:   u16 = 800; pub const IO_END:   u16 = 899;
63}
64
65// -----------------------------------------------------------------------------
66// CORE (001-099) - Fundamental System Health
67// -----------------------------------------------------------------------------
68// ESCALATION: Operational
69// ACTION: Retry / degrade gracefully; alert if persistent
70define_error_codes! {
71    &namespaces::CORE, OperationCategory::System => {
72        CORE_INIT_FAILED           = (1, 600),
73        CORE_SHUTDOWN_FAILED       = (2, 600),
74        CORE_PANIC_RECOVERY        = (3, 700),
75        CORE_INVALID_STATE         = (4, 600),
76        CORE_MEMORY_ALLOC_FAILED   = (5, 700),
77        CORE_THREAD_SPAWN_FAILED   = (6, 600),
78        CORE_MUTEX_LOCK_FAILED     = (7, 600),
79        CORE_SIGNAL_HANDLER_FAILED = (8, 600),
80        CORE_MODULE_LOAD_FAILED    = (9, 600),
81        CORE_DEPENDENCY_MISSING    = (10, 600),
82        CORE_VERSION_CHECK_FAILED  = (11, 600),
83        CORE_RESOURCE_INIT_FAILED  = (12, 600),
84        CORE_EVENT_LOOP_FAILED     = (13, 600),
85        CORE_CONFIG_BOOTSTRAP_FAILED = (14, 600),
86        CORE_DATABASE_CONNECT_FAILED = (15, 600),
87        CORE_CACHE_INIT_FAILED     = (16, 600),
88        CORE_QUEUE_OVERFLOW        = (17, 600),
89        CORE_TIMER_SETUP_FAILED    = (18, 600),
90        CORE_HOOK_REGISTRATION_FAILED = (19, 600),
91        CORE_PLUGIN_INIT_FAILED    = (20, 600),
92        CORE_STATE_TRANSITION_FAILED = (21, 600),
93        CORE_HEALTH_CHECK_FAILED   = (22, 600),
94        CORE_BACKUP_FAILED         = (23, 600),
95        CORE_RESTORE_FAILED        = (24, 600),
96        CORE_MIGRATION_FAILED      = (25, 600),
97        CORE_LICENSE_VALIDATION_FAILED = (26, 600),
98        CORE_AUTH_INIT_FAILED      = (27, 600),
99        CORE_CRYPTO_SETUP_FAILED   = (28, 600),
100        CORE_NETWORK_INIT_FAILED   = (29, 600),
101        CORE_API_SERVER_START_FAILED = (30, 600),
102    }
103}
104
105// -----------------------------------------------------------------------------
106// CFG (100-199) - Configuration & Validation
107// -----------------------------------------------------------------------------
108// ESCALATION: Operational
109// ACTION: Fallback to defaults; alert on load failures
110define_error_codes! {
111    &namespaces::CFG, OperationCategory::Configuration => {
112        CFG_PARSE_FAILED             = (100, 200),
113        CFG_VALIDATION_FAILED        = (101, 200),
114        CFG_MISSING_REQUIRED         = (102, 200),
115        CFG_INVALID_VALUE            = (103, 200),
116        CFG_INVALID_FORMAT           = (104, 200),
117        CFG_PERMISSION_DENIED        = (105, 200),
118        CFG_VERSION_MISMATCH         = (106, 200),
119        CFG_SECURITY_VIOLATION       = (107, 200),
120        CFG_LOAD_FAILED              = (108, 200),
121        CFG_SAVE_FAILED              = (109, 200),
122        CFG_ENV_VAR_MISSING          = (110, 200),
123        CFG_TYPE_MISMATCH            = (111, 200),
124        CFG_DUPLICATE_KEY            = (112, 200),
125        CFG_SCHEMA_VALIDATION_FAILED = (113, 200),
126        CFG_MERGE_CONFLICT           = (114, 200),
127        CFG_REMOTE_FETCH_FAILED      = (115, 200),
128        CFG_LOCAL_STORE_FAILED       = (116, 200),
129        CFG_ENCRYPTION_FAILED        = (117, 200),
130        CFG_DECRYPTION_FAILED        = (118, 200),
131        CFG_KEY_NOT_FOUND            = (119, 200),
132        CFG_INVALID_PATH             = (120, 200),
133        CFG_CONVERSION_FAILED        = (121, 200),
134        CFG_DEFAULTS_LOAD_FAILED     = (122, 200),
135        CFG_OVERRIDE_FAILED          = (123, 200),
136        CFG_WATCHER_INIT_FAILED      = (124, 200),
137        CFG_RELOAD_FAILED            = (125, 200),
138        CFG_BACKUP_FAILED            = (126, 200),
139        CFG_ROLLBACK_FAILED          = (127, 200),
140        CFG_TEMPLATE_RENDER_FAILED   = (128, 200),
141        CFG_VARIABLE_RESOLUTION_FAILED = (129, 200),
142        CFG_SECRETS_MANAGER_FAILED   = (130, 200),
143        CFG_PROFILE_SWITCH_FAILED    = (131, 200),
144    }
145}
146
147// -----------------------------------------------------------------------------
148// DCP (200-299) - Deception Subsystem
149// -----------------------------------------------------------------------------
150
151// Block 1: Deployment Infrastructure (The "Stage")
152// These are technical failures. The show cannot go on because the lights broke.
153// ESCALATION: Operational
154// ACTION: Retry deployment; fallback to static artifacts if persistent
155define_error_codes! {
156    &namespaces::DCP, OperationCategory::Deployment => {
157        DCP_DEPLOY_FAILED            = (200, 300),
158        DCP_ARTIFACT_CREATE          = (201, 300),
159        DCP_ARTIFACT_WRITE           = (202, 300),
160        DCP_CLEANUP_FAILED           = (203, 300),
161        DCP_TAG_GENERATION           = (204, 300),
162        DCP_TRIGGER_FAILED           = (205, 300),
163        DCP_SIMULATION_FAILED        = (206, 300),
164        DCP_BAIT_DEPLOY_FAILED       = (207, 300),
165        DCP_HONEYPOT_INIT_FAILED     = (208, 300),
166        DCP_FAKE_DATA_GENERATION_FAILED = (209, 300),
167        DCP_REDIRECT_SETUP_FAILED    = (210, 300),
168        DCP_MIMICRY_FAILED           = (211, 300),
169        DCP_TARPIT_ENGAGE_FAILED     = (212, 300),
170        DCP_DECOY_LAUNCH_FAILED      = (213, 300),
171        DCP_SHADOW_SYSTEM_FAILED     = (214, 300),
172        DCP_FINGERPRINT_MISMATCH     = (215, 300),
173        DCP_BEHAVIOR_MODEL_LOAD_FAILED = (216, 300),
174        DCP_INTRUSION_SIM_FAILED     = (217, 300),
175        DCP_COUNTERMEASURE_FAILED    = (218, 300),
176        DCP_ARTIFACT_EXPIRATION      = (219, 300),
177        DCP_DEPLOYMENT_ROLLBACK_FAILED = (220, 300),
178        DCP_RESOURCE_ALLOCATION_FAILED = (221, 300),
179        DCP_TEMPLATE_LOAD_FAILED     = (222, 300),
180        DCP_VALIDATION_CHECK_FAILED  = (223, 300),
181        DCP_INTEGRITY_CHECK_FAILED   = (224, 300),
182        DCP_NETWORK_SIM_FAILED       = (225, 300),
183        DCP_ACCESS_CONTROL_FAILED    = (226, 300),
184        DCP_ENCRYPTED_ARTIFACT_FAILED = (227, 300),
185        DCP_DECRYPT_ARTIFACT_FAILED  = (228, 300),
186        DCP_DYNAMIC_GENERATION_FAILED = (229, 300),
187        DCP_PERSISTENCE_FAILED       = (230, 300),
188    }
189}
190
191// Block 2: Narrative & Perception (The "Script")
192// These are semantic failures. The infrastructure is fine, but the lie is discovered.
193//
194// ESCALATION PROTOCOL:
195// - DESYNC/STATE_VIOLATION: Strategic
196// ACTION: Log and soft-reset artifact; analyst review
197// - NARRATIVE_BREAK: Critical
198// ACTION: Immediate hard-reset of persona. Attacker knows.
199// - ADVERSARY_ADAPTATION: Critical
200// ACTION: Trigger high-alert. Attacker is playing back.
201define_error_codes! {
202    &namespaces::DCP, OperationCategory::Deception => {
203        // Internal truth diverged from exposed lie (e.g., Hostname mismatch).
204        DCP_NARRATIVE_DESYNC         = (231, 500),
205        
206        // Attacker-visible inconsistency detected.
207        // IMPACT: DeceptionFailure. The lie has crumbled.
208        DCP_NARRATIVE_BREAK          = (232, 800),
209        
210        // Deception efficacy statistically failing based on interaction depth.
211        DCP_BELIEVABILITY_LOW        = (233, 500),
212        
213        // Attacker changing behavior in response to deception.
214        // NOTE: This effectively functions as the "Perception" layer.
215        DCP_ADVERSARY_ADAPTATION     = (234, 800),
216        
217        // Artifact accessed in an impossible state (e.g., accessed after delete).
218        DCP_STATE_VIOLATION          = (235, 500),
219        
220        // Causality breach (Effect before Cause in narrative).
221        DCP_TEMPORAL_INCONSISTENCY   = (236, 500),
222        
223        // Interaction sequence physically impossible.
224        DCP_CAUSALITY_BREACH         = (237, 500),
225    }
226}
227
228// -----------------------------------------------------------------------------
229// TEL (300-399) - Telemetry & Observability
230// -----------------------------------------------------------------------------
231// ESCALATION: Operational (most); Strategic for evasion
232// ACTION: Fallback monitoring; alert on gaps/evasion
233define_error_codes! {
234    &namespaces::TEL, OperationCategory::Monitoring => {
235        TEL_INIT_FAILED              = (300, 400),
236        TEL_WATCH_FAILED             = (301, 400),
237        TEL_EVENT_LOST               = (302, 400),
238        TEL_CHANNEL_CLOSED           = (303, 400),
239        TEL_MONITOR_CRASH            = (304, 400),
240        TEL_METRIC_COLLECTION_FAILED = (305, 400),
241        TEL_EXPORT_FAILED            = (306, 400),
242        TEL_AGGREGATION_FAILED       = (307, 400),
243        TEL_TRACE_SPAN_FAILED        = (308, 400),
244        TEL_REMOTE_SEND_FAILED       = (309, 400),
245        TEL_BUFFER_OVERFLOW          = (310, 400),
246        TEL_INVALID_METRIC           = (311, 400),
247        TEL_SAMPLING_FAILED          = (312, 400),
248        TEL_PROPAGATION_FAILED       = (313, 400),
249        TEL_ENDPOINT_UNREACHABLE     = (314, 400),
250        TEL_AUTH_FAILED              = (315, 400),
251        TEL_COMPRESSION_FAILED       = (316, 400),
252        TEL_DECOMPRESSION_FAILED     = (317, 400),
253        TEL_FILTER_APPLY_FAILED      = (318, 400),
254        TEL_ALERT_TRIGGER_FAILED     = (319, 400),
255        TEL_DASHBOARD_UPDATE_FAILED  = (320, 400),
256        TEL_LOG_INGEST_FAILED        = (321, 400),
257        TEL_QUERY_FAILED             = (322, 400),
258        TEL_RETENTION_POLICY_FAILED  = (323, 400),
259        TEL_BACKPRESSURE             = (324, 400),
260        TEL_INSTRUMENTATION_FAILED   = (325, 400),
261        TEL_BATCH_PROCESS_FAILED     = (326, 400),
262        TEL_SERIALIZATION_FAILED     = (327, 400),
263        TEL_DESERIALIZATION_FAILED   = (328, 400),
264        TEL_RESOURCE_MONITOR_FAILED  = (329, 400),
265        TEL_HEARTBEAT_FAILED         = (330, 400),
266        
267        // Adversarial Telemetry Issues (Contested Environment)
268        // Telemetry evasion detected (Attacker blinding sensors).
269        // IMPACT: ExposureRisk.
270        TEL_EVASION_DETECTED         = (331, 800),
271        // Sensor bypass attempt detected.
272        TEL_SENSOR_BYPASS            = (332, 700),
273        // Critical observability blind spot identified.
274        TEL_OBSERVABILITY_GAP        = (333, 700),
275    }
276}
277
278// -----------------------------------------------------------------------------
279// COR (400-499) - Correlation & Analysis
280// -----------------------------------------------------------------------------
281// ESCALATION: Epistemic (most); Strategic for invalidation
282// ACTION: Model retrain; analyst review on hypothesis shifts
283define_error_codes! {
284    &namespaces::COR, OperationCategory::Analysis => {
285        COR_RULE_EVAL_FAILED         = (400, 300),
286        COR_BUFFER_OVERFLOW          = (401, 300),
287        COR_INVALID_SCORE            = (402, 300),
288        COR_WINDOW_EXPIRED           = (403, 300),
289        COR_INVALID_ARTIFACT         = (404, 300),
290        COR_PATTERN_MATCH_FAILED     = (405, 300),
291        COR_DATA_INGEST_FAILED       = (406, 300),
292        COR_AGGREGATION_FAILED       = (407, 300),
293        COR_THRESHOLD_BREACH         = (408, 300),
294        COR_FALSE_POSITIVE           = (409, 300),
295        COR_EVENT_MERGE_FAILED       = (410, 300),
296        COR_CONTEXT_LOAD_FAILED      = (411, 300),
297        COR_ANOMALY_DETECT_FAILED    = (412, 300),
298        COR_MODEL_TRAIN_FAILED       = (413, 300),
299        COR_INFERENCE_FAILED         = (414, 300),
300        COR_DATA_NORMALIZATION_FAILED = (415, 300),
301        COR_FEATURE_EXTRACTION_FAILED = (416, 300),
302        COR_CLUSTERING_FAILED        = (417, 300),
303        COR_OUTLIER_DETECTION_FAILED = (418, 300),
304        COR_TIME_SERIES_ANALYSIS_FAILED = (419, 300),
305        COR_GRAPH_BUILD_FAILED       = (420, 300),
306        COR_PATH_ANALYSIS_FAILED     = (421, 300),
307        COR_RULE_UPDATE_FAILED       = (422, 300),
308        COR_VALIDATION_FAILED        = (423, 300),
309        COR_EXPORT_FAILED            = (424, 300),
310        COR_IMPORT_FAILED            = (425, 300),
311        COR_QUERY_EXEC_FAILED        = (426, 300),
312        COR_INDEX_BUILD_FAILED       = (427, 300),
313        COR_SEARCH_FAILED            = (428, 300),
314        COR_ENRICHMENT_FAILED        = (429, 300),
315        COR_DEDUPLICATION_FAILED     = (430, 300),
316        
317        // Hypothesis & Intent Analysis
318        // Correlation confidence dropped below actionable threshold.
319        COR_CONFIDENCE_DEGRADATION   = (431, 300),
320        // Behavioral model drift detected (Attacker changed tactics).
321        COR_MODEL_DRIFT              = (432, 300),
322        // Current attribution hypothesis invalidated by new data.
323        COR_HYPOTHESIS_INVALIDATED   = (433, 550),
324        // Conflicting signals suggest multiple actors or misattribution.
325        COR_ACTOR_CONFLICT           = (434, 300),
326    }
327}
328
329// -----------------------------------------------------------------------------
330// RSP (500-599) - Response & Action
331// -----------------------------------------------------------------------------
332// ESCALATION: Operational (most); Strategic for anomalies
333// ACTION: Fallback response; analyst review on behavioral issues
334define_error_codes! {
335    &namespaces::RSP, OperationCategory::Response => {
336        RSP_EXEC_FAILED              = (500, 300),
337        RSP_TIMEOUT                  = (501, 300),
338        RSP_INVALID_ACTION           = (502, 300),
339        RSP_RATE_LIMITED             = (503, 300),
340        RSP_HANDLER_NOT_FOUND        = (504, 300),
341        RSP_SERIALIZATION_FAILED     = (505, 300),
342        RSP_DESERIALIZATION_FAILED   = (506, 300),
343        RSP_VALIDATION_FAILED        = (507, 300),
344        RSP_AUTH_FAILED              = (508, 300),
345        RSP_PERMISSION_DENIED        = (509, 300),
346        RSP_RESOURCE_NOT_FOUND       = (510, 300),
347        RSP_CONFLICT                 = (511, 300),
348        RSP_INTERNAL_ERROR           = (512, 300),
349        RSP_BAD_REQUEST              = (513, 300),
350        RSP_UNAVAILABLE              = (514, 300),
351        RSP_GATEWAY_TIMEOUT          = (515, 300),
352        RSP_TOO_MANY_REQUESTS        = (516, 300),
353        RSP_PAYLOAD_TOO_LARGE        = (517, 300),
354        RSP_UNSUPPORTED_MEDIA        = (518, 300),
355        RSP_METHOD_NOT_ALLOWED       = (519, 300),
356        RSP_NOT_ACCEPTABLE           = (520, 300),
357        RSP_PROXY_AUTH_REQUIRED      = (521, 300),
358        RSP_REQUEST_TIMEOUT          = (522, 300),
359        RSP_PRECONDITION_FAILED      = (523, 300),
360        RSP_EXPECTATION_FAILED       = (524, 300),
361        RSP_MISDIRECTED_REQUEST      = (525, 300),
362        RSP_UNPROCESSABLE_ENTITY     = (526, 300),
363        RSP_LOCKED                   = (527, 300),
364        RSP_FAILED_DEPENDENCY        = (528, 300),
365        RSP_UPGRADE_REQUIRED         = (529, 300),
366        RSP_PRECONDITION_REQUIRED    = (530, 300),
367
368        // Adversary-Shaped Response Failures (Leakage)
369        // Response timing unnatural (too fast/slow), risking exposure.
370        RSP_TIMING_ANOMALY           = (531, 500),
371        // Response entropy too low (too repetitive), risking pattern detection.
372        RSP_ENTROPY_LOW              = (532, 500),
373        // Response behavior inconsistent with emulated persona.
374        RSP_BEHAVIORAL_INCONSISTENCY = (533, 500),
375    }
376}
377
378// -----------------------------------------------------------------------------
379// LOG (600-699) - Audit & Logging
380// -----------------------------------------------------------------------------
381// ESCALATION: Operational
382// ACTION: Fallback to stderr; alert on persistent failures
383define_error_codes! {
384    &namespaces::LOG, OperationCategory::Audit => {
385        LOG_WRITE_FAILED             = (600, 200),
386        LOG_ROTATE_FAILED            = (601, 200),
387        LOG_BUFFER_FULL              = (602, 200),
388        LOG_SERIALIZATION            = (603, 200),
389        LOG_INIT_FAILED              = (604, 200),
390        LOG_FLUSH_FAILED             = (605, 200),
391        LOG_LEVEL_INVALID            = (606, 200),
392        LOG_FILTER_APPLY_FAILED      = (607, 200),
393        LOG_APPENDER_FAILED          = (608, 200),
394        LOG_REMOTE_SEND_FAILED       = (609, 200),
395        LOG_COMPRESSION_FAILED       = (610, 200),
396        LOG_ENCRYPTION_FAILED        = (611, 200),
397        LOG_ARCHIVE_FAILED           = (612, 200),
398        LOG_PURGE_FAILED             = (613, 200),
399        LOG_INDEX_FAILED             = (614, 200),
400        LOG_SEARCH_FAILED            = (615, 200),
401        LOG_PARSE_FAILED             = (616, 200),
402        LOG_FORMAT_INVALID           = (617, 200),
403        LOG_TIMESTAMP_FAILED         = (618, 200),
404        LOG_METADATA_MISSING         = (619, 200),
405        LOG_ROLLOVER_FAILED          = (620, 200),
406        LOG_BACKUP_FAILED            = (621, 200),
407        LOG_RESTORE_FAILED           = (622, 200),
408        LOG_QUEUE_OVERFLOW           = (623, 200),
409        LOG_ASYNC_SEND_FAILED        = (624, 200),
410        LOG_SYNC_FAILED              = (625, 200),
411        LOG_HANDLER_CRASH            = (626, 200),
412        LOG_CONFIG_LOAD_FAILED       = (627, 200),
413        LOG_RELOAD_FAILED            = (628, 200),
414        LOG_EXPORT_FAILED            = (629, 200),
415        LOG_IMPORT_FAILED            = (630, 200),
416    }
417}
418
419// -----------------------------------------------------------------------------
420// PLT (700-799) - Platform & OS
421// -----------------------------------------------------------------------------
422// ESCALATION: Operational
423// ACTION: Graceful degrade; alert on compatibility issues
424define_error_codes! {
425    &namespaces::PLT, OperationCategory::System => {
426        PLT_UNSUPPORTED              = (700, 400),
427        PLT_SYSCALL_FAILED           = (701, 400),
428        PLT_PERMISSION_DENIED        = (702, 400),
429        PLT_RESOURCE_EXHAUSTED       = (703, 400),
430        PLT_OS_VERSION_MISMATCH      = (704, 400),
431        PLT_HARDWARE_UNSUPPORTED     = (705, 400),
432        PLT_DRIVER_LOAD_FAILED       = (706, 400),
433        PLT_API_CALL_FAILED          = (707, 400),
434        PLT_ENV_DETECT_FAILED        = (708, 400),
435        PLT_VIRTUALIZATION_FAILED    = (709, 400),
436        PLT_CONTAINER_INIT_FAILED    = (710, 400),
437        PLT_KERNEL_MODULE_FAILED     = (711, 400),
438        PLT_FILESYSTEM_MOUNT_FAILED  = (712, 400),
439        PLT_NETWORK_INTERFACE_FAILED = (713, 400),
440        PLT_PROCESS_SPAWN_FAILED     = (714, 400),
441        PLT_SIGNAL_SEND_FAILED       = (715, 400),
442        PLT_MEMORY_MAP_FAILED        = (716, 400),
443        PLT_THREAD_AFFINITY_FAILED   = (717, 400),
444        PLT_POWER_MANAGEMENT_FAILED  = (718, 400),
445        PLT_BOOTSTRAP_FAILED         = (719, 400),
446        PLT_SHUTDOWN_HOOK_FAILED     = (720, 400),
447        PLT_COMPATIBILITY_CHECK_FAILED = (721, 400),
448        PLT_LIBRARY_LOAD_FAILED      = (722, 400),
449        PLT_SYMBOL_RESOLVE_FAILED    = (723, 400),
450        PLT_SECURITY_POLICY_FAILED   = (724, 400),
451        PLT_AUDIT_HOOK_FAILED        = (725, 400),
452        PLT_RESOURCE_LIMIT_REACHED   = (726, 400),
453        PLT_CLOCK_SYNC_FAILED        = (727, 400),
454        PLT_DEVICE_ACCESS_FAILED     = (728, 400),
455        PLT_FIRMWARE_UPDATE_FAILED   = (729, 400),
456        PLT_BIOS_CONFIG_FAILED       = (730, 400),
457    }
458}
459
460// -----------------------------------------------------------------------------
461// IO (800-899) - Input/Output & Networking
462// -----------------------------------------------------------------------------
463// ESCALATION: Operational
464// ACTION: Retry with backoff; fallback to in-memory if persistent
465define_error_codes! {
466    &namespaces::IO, OperationCategory::IO => {
467        IO_READ_FAILED               = (800, 200),
468        IO_WRITE_FAILED              = (801, 200),
469        IO_NETWORK_ERROR             = (802, 200),
470        IO_TIMEOUT                   = (803, 200),
471        IO_NOT_FOUND                 = (804, 200),
472        IO_METADATA_FAILED           = (805, 200),
473        IO_OPEN_FAILED               = (806, 200),
474        IO_CLOSE_FAILED              = (807, 200),
475        IO_SEEK_FAILED               = (808, 200),
476        IO_FLUSH_FAILED              = (809, 200),
477        IO_PERMISSION_DENIED         = (810, 200),
478        IO_INTERRUPTED               = (811, 200),
479        IO_WOULD_BLOCK               = (812, 200),
480        IO_INVALID_INPUT             = (813, 200),
481        IO_BROKEN_PIPE               = (814, 200),
482        IO_CONNECTION_RESET          = (815, 200),
483        IO_CONNECTION_REFUSED        = (816, 200),
484        IO_NOT_CONNECTED             = (817, 200),
485        IO_ADDR_IN_USE               = (818, 200),
486        IO_ADDR_NOT_AVAILABLE        = (819, 200),
487        IO_NETWORK_DOWN              = (820, 200),
488        IO_NETWORK_UNREACHABLE       = (821, 200),
489        IO_HOST_UNREACHABLE          = (822, 200),
490        IO_ALREADY_EXISTS            = (823, 200),
491        IO_IS_DIRECTORY              = (824, 200),
492        IO_NOT_DIRECTORY             = (825, 200),
493        IO_DIRECTORY_NOT_EMPTY       = (826, 200),
494        IO_READ_ONLY_FS              = (827, 200),
495        IO_FS_QUOTA_EXCEEDED         = (828, 200),
496        IO_STALE_NFS_HANDLE          = (829, 200),
497        IO_REMOTE_IO                 = (830, 200),
498    }
499}
500
501#[cfg(test)]
502mod tests {
503    use super::*;
504    use crate::ErrorImpact;
505
506    /// Enforce that all defined error codes fall within their assigned namespace ranges.
507    /// This prevents "governance drift" where developers add codes ad-hoc.
508    #[test]
509    fn enforce_namespace_ranges() {
510        // Validate Core Ranges
511        assert!(CORE_INIT_FAILED.code() >= ranges::CORE_START && CORE_INIT_FAILED.code() <= ranges::CORE_END);
512        assert!(CORE_API_SERVER_START_FAILED.code() <= ranges::CORE_END);
513
514        // Validate DCP Ranges
515        assert!(DCP_DEPLOY_FAILED.code() >= ranges::DCP_START);
516        assert!(DCP_CAUSALITY_BREACH.code() <= ranges::DCP_END);
517
518        // Validate IO Ranges
519        assert!(IO_READ_FAILED.code() >= ranges::IO_START);
520        assert!(IO_REMOTE_IO.code() <= ranges::IO_END);
521        
522        // Ensure gap between blocks (Sanity check)
523        assert!(ranges::DCP_END < ranges::TEL_START);
524    }
525
526    #[test]
527    fn validate_critical_impact_mappings() {
528        assert_eq!(DCP_NARRATIVE_BREAK.impact_level(), ErrorImpact::Collapse);
529        assert_eq!(TEL_EVASION_DETECTED.impact_level(), ErrorImpact::Collapse);
530        assert_eq!(CORE_MEMORY_ALLOC_FAILED.impact_level(), ErrorImpact::Leak);
531    }
532}