{"record":{"id":"60fdf690e158418c","repo":"pydantic/monty","slug":"test-function-name-not-found","errorCode":null,"errorMessage":"test function '{name}' not found","messagePattern":"test function '(.+?)' not found","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/monty/src/intern.rs","lineNumber":1671,"sourceCode":"\n    /// Lookup a function by its `FunctionId`\n    ///\n    /// # Panics\n    ///\n    /// Panics if the `FunctionId` is invalid.\n    #[inline]\n    pub fn get_function(&self, id: FunctionId) -> &Function {\n        self.functions.get(id.index()).expect(\"Function not found\")\n    }\n\n    /// Injects `fault` into the named function's metadata.\n    #[cfg(feature = \"test-hooks\")]\n    pub(crate) fn corrupt_function_metadata_for_tests(&mut self, name: &str, fault: FunctionMetadataFault) {\n        let index = self\n            .functions\n            .iter()\n            .position(|function| self.get_str(function.name.name_id) == name)\n            .unwrap_or_else(|| panic!(\"test function '{name}' not found\"));\n        self.functions[index].corrupt_metadata_for_tests(fault);\n    }\n\n    /// Returns the Python hash for an interned string.\n    ///\n    /// Dispatches by id range:\n    /// * ASCII (`id < 128`): looks up [`ASCII_HASHES`] (per-slot lazy);\n    ///   computes via [`hash_python_str`] on first use of that byte.\n    /// * Static (`id < INTERN_STRING_ID_OFFSET`): looks up [`STATIC_HASHES`]\n    ///   (per-slot lazy); computes from the variant's `&'static str` on\n    ///   first use of that variant.\n    /// * Interned (`id >= INTERN_STRING_ID_OFFSET`): reads the [`HashValue`]\n    ///   from the corresponding [`WithHash`] entry — populated eagerly at\n    ///   intern time.\n    ///\n    /// All three paths must agree with [`hash_python_str`] applied to the\n    /// underlying `&str` — interned and heap strings with equal contents\n    /// must hash identically.","sourceCodeStart":1653,"sourceCodeEnd":1689,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty/src/intern.rs#L1653-L1689","documentation":"A test-only hook that deliberately corrupts function metadata must be told which Python-level function name to corrupt; if no interned function in the VM has that name, the hook panics. It is a test-harness lookup failure, not a runtime error user code can hit.","triggerScenarios":"Calling `vm.corrupt_function_metadata_for_tests(name, fault)` under the `test-hooks` feature with a name that matches no function currently prepared in the VM (typo, function never defined, or defined after the call).","commonSituations":"Writing or renaming fault-injection tests for function metadata; test setup order changed so the function isn't compiled yet when the hook runs.","solutions":["Check the exact function name as it appears in the test's Python source (including case).","Ensure the code defining the function is prepared/compiled before calling the hook.","Verify the `test-hooks` feature is enabled on the build, so the hook and its metadata path match.","Enumerate `vm.functions` names in a debug print to see available candidates."],"exampleFix":"// before\nvm.corrupt_function_metadata_for_tests('frube', FunctionMetadataFault::BadCode);\n// after\nvm.corrupt_function_metadata_for_tests('frobnicate', FunctionMetadataFault::BadCode);","handlingStrategy":"validation","validationCode":"// in tests, before calling the hook\nlet names: Vec<String> = vm.functions.iter().map(|f| vm.get_str(f.name.name_id).to_owned()).collect();\nassert!(names.iter().any(|n| n == name), 'function {name} not prepared');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Compile/prepare the Python code before invoking test hooks","Copy function names exactly from the test source","Add a helper listing prepared function names when a hook lookup fails"],"tags":["rust","test-hooks","internal"],"backgroundTag":"record-not-found","analyzedSha":"adc986b362e3961f407868cb118a99fe831b9e61","analyzedAt":"2026-09-13T19:19:18.698Z","contentChangedAt":"2026-09-13T19:19:18.698Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}