{"record":{"id":"fbfdf5d2bc0a7c62","repo":"nautechsystems/nautilus_trader","slug":"writing-to-string-should-not-fail-fbfdf5","errorCode":null,"errorMessage":"writing to String should not fail","messagePattern":"writing to String should not fail","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"crates/common/src/generators/order_list_id.rs","lineNumber":163,"sourceCode":"        Timestamp::from_second(\n            i64::try_from(epoch_second).expect(\"seconds timestamp should fit i64\"),\n        )\n        .expect(\"seconds timestamp should be within valid range\"),\n    );\n\n    buf.clear();\n\n    write!(\n        buf,\n        \"OL-{:04}{:02}{:02}-{:02}{:02}{:02}-{trader_tag}-{strategy_tag}-\",\n        now_utc.year(),\n        now_utc.month(),\n        now_utc.day(),\n        now_utc.hour(),\n        now_utc.minute(),\n        now_utc.second(),\n    )\n    .expect(\"writing to String should not fail\");\n}\n\n#[cfg(test)]\nmod tests {\n    use std::{cell::RefCell, rc::Rc};\n\n    use nautilus_core::UnixNanos;\n    use nautilus_model::{\n        identifiers::{OrderListId, StrategyId, TraderId},\n        stubs::TestDefault,\n    };\n    use rstest::rstest;\n\n    use crate::{clock::TestClock, generators::order_list_id::OrderListIdGenerator};\n\n    fn get_order_list_id_generator(initial_count: Option<usize>) -> OrderListIdGenerator {\n        let clock = Rc::new(RefCell::new(TestClock::new()));\n        OrderListIdGenerator::new(","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/generators/order_list_id.rs#L145-L181","documentation":"This panic comes from `.expect(\"writing to String should not fail\")` on the result of `write!(buf, ...)` in `write_fixed_prefix` in crates/common/src/generators/order_list_id.rs. Formatting into a `String` via `std::fmt::Write` is infallible in practice — a `String` never fails to grow except on allocation failure — so the code asserts this invariant. The panic indicates an impossible formatter state, essentially an internal invariant violation.","triggerScenarios":"Calling `refresh_fixed_prefix` triggers the write!; the expect only fires if the fmt::Write impl for String errors, which in practice only happens on memory allocation failure (OOM).","commonSituations":"Effectively never hit by users; could surface under extreme memory exhaustion, or indicate corrupted inputs such as a trader/strategy tag with invalid formatting width specifiers (not possible with plain Display).","solutions":["Check system memory conditions if this genuinely fires; it signals OOM, not bad input","Do not attempt to handle it — it is a deliberate internal invariant assertion","If you need graceful degradation, use `write!` result handling upstream instead of expect (requires library change)"],"exampleFix":"null","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"// String fmt::Write is infallible except on OOM; no meaningful catch pattern\nlet _ = write!(buf, \"...\"); // or keep expect as internal invariant","preventionTips":["Treat fmt::Write-into-String as infallible; do not attempt recovery","Monitor process memory if allocation failures are plausible"],"tags":["rust","panic","invariant","formatting"],"backgroundTag":"internal-invariant-violation","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"}