{"record":{"id":"c208812c456d53fb","repo":"nautechsystems/nautilus_trader","slug":"writing-to-string-should-not-fail-c20881","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/position_id.rs","lineNumber":150,"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        \"P-{:04}{:02}{:02}-{:02}{:02}{:02}-{trader_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::{PositionId, StrategyId, TraderId},\n        stubs::TestDefault,\n    };\n    use rstest::rstest;\n\n    use crate::{clock::TestClock, generators::position_id::PositionIdGenerator};\n\n    fn get_position_id_generator() -> PositionIdGenerator {\n        PositionIdGenerator::new(\n            TraderId::test_default(),","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/generators/position_id.rs#L132-L168","documentation":"This panic comes from `.expect(\"writing to String should not fail\")` on the `write!(buf, ...)` result in `write_fixed_prefix` in crates/common/src/generators/position_id.rs. Formatting the date-time components into a `String` cannot fail under normal operation because `String`'s `fmt::Write` implementation only errors on allocation failure, so the code asserts the invariant with expect.","triggerScenarios":"Reached on every `refresh_fixed_prefix` call; only panics if the underlying String write fails, which in practice means memory allocation failure (OOM).","commonSituations":"Effectively never encountered by library users; would only appear under severe memory exhaustion in the host process.","solutions":["Treat it as an internal invariant assertion, not a user-facing error","Check host memory if it ever fires; free memory or reduce allocation pressure","Upstream alternative: return Result from write_fixed_prefix instead of expecting (library change)"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"// infallible except OOM; no meaningful catch pattern","preventionTips":["Do not handle; this is an internal invariant assertion","Ensure adequate host memory"],"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"}