{"record":{"id":"77bc99185cf48b46","repo":"pydantic/monty","slug":"test-function-has-an-owned-cell","errorCode":null,"errorMessage":"test function has an owned cell","messagePattern":"test function has an owned cell","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/monty/src/function.rs","lineNumber":322,"sourceCode":"            None\n        }\n    }\n\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","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty/src/function.rs#L304-L340","documentation":"This panic comes from an `expect` in `FunctionMetadata::corrupt_metadata_for_tests`, a test-only fault injector that deliberately corrupts function metadata to test deserializer validation. It fires when the `CellVarLengthMismatch` fault is requested but the target function metadata has no cell param indices to pop, meaning the test fixture was built without an owned cell variable. It indicates the test setup, not the code under test, is wrong.","triggerScenarios":"Calling `corrupt_metadata_for_tests(FunctionMetadataFault::CellVarLengthMismatch)` on function metadata whose `cell_param_indices` vec is empty (a function compiled without cell variables).","commonSituations":"Writing a new roundtrip/deserialization fuzz or fault test against a helper function that has no closures or cell variables; refactoring a test fixture so the function no longer captures cells while the fault list still assumes one.","solutions":["Fix the test fixture so the function metadata actually contains a cell param index before applying the fault (compile a function with a closure capturing a cell).","Pick a different fault variant applicable to metadata that exists (e.g. namespace-size faults).","Guard the fault application with an `if !self.cell_param_indices.is_empty()` check in the fault injector or skip the case in the test matrix."],"exampleFix":"// before\nfn fixture() -> FunctionMetadata { /* function without cells */ make_metadata('f') }\nlet mut m = fixture();\nm.corrupt_metadata_for_tests(FunctionMetadataFault::CellVarLengthMismatch); // panics\n// after\nlet mut m = make_metadata_with_cell('f'); // function capturing a cell variable\nm.corrupt_metadata_for_tests(FunctionMetadataFault::CellVarLengthMismatch);","handlingStrategy":"validation","validationCode":"assert!(!metadata.cell_param_indices.is_empty(), 'fixture must have a cell param for CellVarLengthMismatch');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build fixtures that satisfy every fault's preconditions (cells, free vars, cell params).","Apply faults to fresh clones, never stacked.","Keep fault applicability checks inside the injector where possible."],"tags":["rust","test-fixture","panic","internal-invariant"],"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"}