{"record":{"id":"0594b43f55368659","repo":"pydantic/monty","slug":"test-namespace-fits-in-u16","errorCode":null,"errorMessage":"test namespace fits in u16","messagePattern":"test namespace fits in u16","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/monty/src/function.rs","lineNumber":325,"sourceCode":"\n    /// Injects a metadata fault for dump validation tests.\n    #[cfg(feature = \"test-hooks\")]\n    pub(crate) fn corrupt_metadata_for_tests(&mut self, fault: FunctionMetadataFault) {\n        match fault {\n            FunctionMetadataFault::SignatureSlotsBeyondNamespace => {\n                self.namespace_size = self.signature.total_slots() - 1;\n            }\n            FunctionMetadataFault::NamespaceTooLarge => {\n                self.namespace_size = usize::from(u16::MAX) + 1;\n            }\n            FunctionMetadataFault::FreeVarLengthMismatch => {\n                self.free_var_slots.pop().expect(\"test function has a free variable\");\n            }\n            FunctionMetadataFault::CellVarLengthMismatch => {\n                self.cell_param_indices.pop().expect(\"test function has an owned cell\");\n            }\n            FunctionMetadataFault::FreeVarSlotOutOfRange => {\n                let slot = NamespaceId::new(self.namespace_size).expect(\"test namespace fits in u16\");\n                *self\n                    .free_var_slots\n                    .first_mut()\n                    .expect(\"test function has a free variable\") = slot;\n            }\n            FunctionMetadataFault::CellVarSlotOutOfRange => {\n                let slot = NamespaceId::new(self.namespace_size).expect(\"test namespace fits in u16\");\n                *self\n                    .cell_var_slots\n                    .first_mut()\n                    .expect(\"test function has an owned cell\") = slot;\n            }\n            FunctionMetadataFault::CellParamIndexOutOfRange => {\n                *self\n                    .cell_param_indices\n                    .first_mut()\n                    .expect(\"test function has an owned cell\") = Some(self.signature.total_slots());\n            }","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty/src/function.rs#L307-L343","documentation":"This panic is an `expect` in the test-only fault injector `corrupt_metadata_for_tests`, raised when `NamespaceId::new(self.namespace_size)` returns `None` while setting up the `FreeVarSlotOutOfRange` fault. It means the current `namespace_size` cannot be converted into a valid `NamespaceId`, i.e. the size exceeds `u16::MAX` or is otherwise invalid, so the test cannot construct an out-of-range slot value. It signals bad test fixture state, not a runtime bug.","triggerScenarios":"Calling `corrupt_metadata_for_tests(FunctionMetadataFault::FreeVarSlotOutOfRange)` (or `CellVarSlotOutOfRange`) on metadata whose `namespace_size` is 0 or above `u16::MAX`, so `NamespaceId::new` fails.","commonSituations":"A prior fault step (e.g. `NamespaceSizeTooLarge`) already corrupted `namespace_size` before the slot fault is applied; composing faults in an order the injector does not support.","solutions":["Reorder faults so slot-range faults run before any fault that corrupts `namespace_size`.","Rebuild fresh metadata for each fault instead of stacking faults on the same object.","Use a fixed known-valid slot constant for the fault instead of deriving it from the (possibly corrupted) `namespace_size`."],"exampleFix":"// before\nlet mut m = metadata.clone();\nm.corrupt_metadata_for_tests(FunctionMetadataFault::NamespaceSizeTooLarge);\nm.corrupt_metadata_for_tests(FunctionMetadataFault::FreeVarSlotOutOfRange); // panics\n// after\nlet mut m = metadata.clone();\nm.corrupt_metadata_for_tests(FunctionMetadataFault::FreeVarSlotOutOfRange); // valid namespace_size here\nm = metadata.clone();\nm.corrupt_metadata_for_tests(FunctionMetadataFault::NamespaceSizeTooLarge);","handlingStrategy":"validation","validationCode":"assert!(metadata.namespace_size > 0 && metadata.namespace_size <= usize::from(u16::MAX), 'namespace_size must be a valid NamespaceId before slot faults');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Order faults so slot-range faults precede namespace-size corruption.","Clone fresh metadata per fault case.","Document fault ordering constraints in the fault enum docs."],"tags":["rust","test-fixture","panic","namespace-id"],"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-14T11:17:12.474Z"}