{"record":{"id":"3d6fcc8861a7194b","repo":"pydantic/monty","slug":"staticstrings-serialization-cannot-fail","errorCode":null,"errorMessage":"StaticStrings serialization cannot fail","messagePattern":"StaticStrings serialization cannot fail","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/monty/src/intern.rs","lineNumber":1245,"sourceCode":"        {\n            *hash ^= u64::from(byte);\n            *hash = hash.wrapping_mul(PRIME);\n        }\n        for byte in bytes {\n            *hash ^= u64::from(*byte);\n            *hash = hash.wrapping_mul(PRIME);\n        }\n    }\n\n    let mut hash = OFFSET_BASIS;\n    for value in StaticStrings::iter() {\n        update(&mut hash, &(value as u16).to_le_bytes());\n        update(&mut hash, format!(\"{value:?}\").as_bytes());\n        let string: &'static str = value.into();\n        update(&mut hash, string.as_bytes());\n        update(\n            &mut hash,\n            &postcard::to_allocvec(&value).expect(\"StaticStrings serialization cannot fail\"),\n        );\n    }\n    hash\n}\n\nimpl StaticStrings {\n    /// Attempts to convert a `StringId` back to a `StaticStrings` variant.\n    ///\n    /// Returns `None` if the `StringId` doesn't correspond to a static string\n    /// (e.g., it's an ASCII char or a dynamically interned string).\n    pub fn from_string_id(id: StringId) -> Option<Self> {\n        u16::try_from(id.0).ok().and_then(Self::from_repr)\n    }\n}\n\n/// Converts this static string variant to its corresponding `StringId`.\nimpl From<StaticStrings> for StringId {\n    fn from(value: StaticStrings) -> Self {","sourceCodeStart":1227,"sourceCodeEnd":1263,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty/src/intern.rs#L1227-L1263","documentation":"An internal `expect` in the test-only `static_strings_fingerprint()`, asserting that postcard serialization of each `StaticStrings` variant into a byte vector cannot fail. Postcard serialization into `to_allocvec` is infallible for these simple enum/static-str payloads, so the assertion documents that no error path needs handling. It fires only if postcard itself returned an error, which would indicate a broken serializer or an unexpectedly complex payload, never user input.","triggerScenarios":"Thrown at crates/monty/src/intern.rs:1245 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["postcard serialization into an allocator-backed Vec of static enum data cannot fail (no io, no size cap); on failure the only cause is a postcard incompatibility, so re-examine the Serialize impls of StaticStrings variants rather than handling the error.","No runtime fallback exists; the fingerprint function is test-only, so a failure should surface as a panic in tests and be fixed at the source."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"adc986b362e3961f407868cb118a99fe831b9e61","analyzedAt":"2026-09-13T19:19:18.698Z","contentChangedAt":"2026-09-13T19:19:18.698Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}