{"record":{"id":"35bea074e806f726","repo":"nautechsystems/nautilus_trader","slug":"invalid-connectionmode-value-value","errorCode":null,"errorMessage":"Invalid `ConnectionMode` value: {value}","messagePattern":"Invalid `ConnectionMode` value: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/network/src/mode.rs","lineNumber":78,"sourceCode":"    /// All associated tasks have been terminated and the connection is no longer available.\n    Closed = 3,\n}\n\nimpl ConnectionMode {\n    /// Converts a `u8` loaded from an [`AtomicU8`] into a [`ConnectionMode`].\n    ///\n    /// # Panics\n    ///\n    /// Panics if `value` is not a valid `ConnectionMode` discriminant (must be between 0 and 3 inclusive).\n    #[inline]\n    #[must_use]\n    pub fn from_u8(value: u8) -> Self {\n        match value {\n            0 => Self::Active,\n            1 => Self::Reconnect,\n            2 => Self::Disconnect,\n            3 => Self::Closed,\n            _ => panic!(\"Invalid `ConnectionMode` value: {value}\"),\n        }\n    }\n\n    /// Loads a [`ConnectionMode`] from an [`AtomicU8`] using sequential consistency.\n    #[inline]\n    #[must_use]\n    pub fn from_atomic(value: &AtomicU8) -> Self {\n        Self::from_u8(value.load(Ordering::SeqCst))\n    }\n\n    /// Atomically transitions to `Reconnect`, but only from `Active`.\n    ///\n    /// Returns `true` if this call performed the transition. A concurrent\n    /// `Disconnect`/`Closed` (or an in-flight `Reconnect`) is left untouched,\n    /// so a writer detecting a dead connection cannot resurrect a client that\n    /// is being torn down.\n    pub fn request_reconnect(value: &AtomicU8) -> bool {\n        Self::request_reconnect_outcome(value) == ReconnectRequestOutcome::Accepted","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/network/src/mode.rs#L60-L96","documentation":"ConnectionMode::from_u8 maps a raw u8 stored in shared state (e.g. an AtomicU8) back to the enum: 0=Active, 1=Reconnect, 2=Disconnect, 3=Closed. Any other value is outside the representable range and panics with this message. It guards against corrupted or uninitialized state bytes.","triggerScenarios":"Calling ConnectionMode::from_u8(v) with v > 3; loading an AtomicU8 that was never initialized with a valid ConnectionMode value; memory/state corruption or writing raw integers into the atomic from another component.","commonSituations":"Restoring connection state from a file/DB where an invalid byte was persisted; a bug writing an out-of-range mode into the shared AtomicU8; manual construction of mode values in tests or bindings passing e.g. 255.","solutions":["Only write values produced by ConnectionMode as u8 into the atomic/state","Validate the raw value is <= 3 before calling from_u8","Initialize the AtomicU8 with a valid ConnectionMode (e.g. Active.as_u8()) at construction","If untrusted input, use a checked mapping (match on the u8) instead of the panicking from_u8"],"exampleFix":"// before\nlet mode = ConnectionMode::from_u8(raw);\n// after\nlet mode = if raw <= 3 { ConnectionMode::from_u8(raw) } else { eprintln!(\"bad connection mode {raw}\"); ConnectionMode::Reconnect };","handlingStrategy":"validation","validationCode":"fn is_valid_connection_mode_u8(v: u8) -> bool { v <= 3 }","typeGuard":null,"tryCatchPattern":"let mode = u8::try_from(raw).ok().filter(|v| *v <= 3).map(ConnectionMode::from_u8).unwrap_or(ConnectionMode::Active);","preventionTips":["Only set the shared AtomicU8 from ConnectionMode::as_u8() values","Initialize atomics with a valid default mode at construction","Validate persisted/loaded state bytes before mapping back to the enum","Never hand-write raw integer mode values in bindings or tests"],"tags":["rust","enum","panic","network"],"backgroundTag":"invalid-enum-value","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}