{"record":{"id":"3977a39cbc0e26e9","repo":"pydantic/monty","slug":"invalid-static-string-id","errorCode":null,"errorMessage":"Invalid static string ID","messagePattern":"Invalid static string ID","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/monty/src/intern.rs","lineNumber":1480,"sourceCode":"    } else if let Ok(ss) = StaticStrings::from_str(s) {\n        Some(ss.into())\n    } else {\n        string_map.get(s).copied()\n    }\n}\n\n/// Looks up a string by its `StringId`.\n///\n/// # Panics\n///\n/// Panics if the `StringId` is invalid - not from this interner or ascii chars or StaticStrings.\nfn get_str(strings: &[WithHash<String>], id: StringId) -> &str {\n    if let Some(ascii_str) = ASCII_STRS.get(id.index()) {\n        ascii_str\n    } else if let Some(intern_index) = id.index().checked_sub(INTERN_STRING_ID_OFFSET) {\n        strings[intern_index].value()\n    } else {\n        let static_str = StaticStrings::from_string_id(id).expect(\"Invalid static string ID\");\n        static_str.into()\n    }\n}\n\n/// Storage for interned strings, bytes, long integers and compiled functions.\n///\n/// This provides lookup by `StringId`, `BytesId`, `LongIntId` and `FunctionId` for interned literals and functions.\n///\n/// # Append-only ownership in the REPL\n///\n/// Ids are stable and only ever appended, so a REPL session never copies this\n/// table: it hands it to each snippet via [`into_builder`](Self::into_builder)\n/// (or extends it in place with [`intern`](Self::intern)) and takes the extended\n/// table back afterwards — whether the snippet succeeded or not.\n///\n/// # Hash tables\n///\n/// Each entry in `strings`/`bytes`/`long_ints` is a [`WithHash`] pairing","sourceCodeStart":1462,"sourceCodeEnd":1498,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty/src/intern.rs#L1462-L1498","documentation":"`get_str` resolves a `StringId` by first checking ASCII single-char strings, then interned strings, then static strings; `StaticStrings::from_string_id` panics if the ID falls in none of the three ranges. A `StringId` outside all valid ranges means heap/table corruption or a bogus ID was constructed.","triggerScenarios":"Calling `get_str` with a `StringId` that is neither an ASCII id, an interned id (>= INTERN_STRING_ID_OFFSET within range), nor a valid `StaticStrings` variant.","commonSituations":"Only from interpreter bugs: corrupted serialized IDs, wrong offset arithmetic, or reading an ID from a snapshot compiled by an incompatible version.","solutions":["Audit how the offending `StringId` was produced; check offset arithmetic against `INTERN_STRING_ID_OFFSET`/static ranges.","If deserializing snapshots/bytecode, ensure the producer and consumer versions match.","Report as an interpreter bug with the failing input."],"exampleFix":"// before\nlet static_str = StaticStrings::from_string_id(id).expect(\"Invalid static string ID\");\n// after\nlet static_str = StaticStrings::from_string_id(id)\n    .ok_or_else(|| InternalError::InvalidStringId(id))?;","handlingStrategy":"validation","validationCode":"fn is_valid_string_id(id: u32, strings_len: usize) -> bool { id < ASCII_STRS_LEN || id >= INTERN_STRING_ID_OFFSET && (id as usize - INTERN_STRING_ID_OFFSET) < strings_len }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never construct StringId outside intern.rs","Match interpreter versions when sharing compiled artifacts","Validate ids after deserialization"],"tags":["rust","panic","interning"],"backgroundTag":"internal-invariant-violation","analyzedSha":"adc986b362e3961f407868cb118a99fe831b9e61","analyzedAt":"2026-09-13T19:19:18.698Z","contentChangedAt":"2026-09-13T19:19:18.698Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}