{"record":{"id":"7e3b9f711e3a5b89","repo":"wasmerio/wasmer","slug":"internal-error-failed-to-resolve-function-e","errorCode":null,"errorMessage":"Internal error: failed to resolve function {}: {e:?}","messagePattern":"Internal error: failed to resolve function (.+?): (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"lib/wasix/src/state/linker/instance_group/imports.rs","lineNumber":331,"sourceCode":"                    let func = self.generate_stub_function(\n                        store,\n                        ty,\n                        env,\n                        module_handle,\n                        import.name().to_owned(),\n                    );\n                    imports.define(import.module(), import.name(), func.clone());\n                }\n                SymbolResolutionResult::FunctionPointer {\n                    resolved_from,\n                    function_table_index,\n                } => {\n                    let func = self.try_instance(*resolved_from).map(|instance| {\n                        instance\n                            .exports\n                            .get_function(import.name())\n                            .unwrap_or_else(|e| {\n                                panic!(\n                                    \"Internal error: failed to resolve function {}: {e:?}\",\n                                    import.name()\n                                )\n                            })\n                    });\n                    match func {\n                        Some(func) => {\n                            trace!(\n                                ?module_handle,\n                                ?import,\n                                function_table_index,\n                                \"Placing function pointer into table\"\n                            );\n                            self.place_in_function_table_at(\n                                store,\n                                func.clone(),\n                                *function_table_index,\n                            )","sourceCodeStart":313,"sourceCodeEnd":349,"githubUrl":"https://github.com/wasmerio/wasmer/blob/8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5/lib/wasix/src/state/linker/instance_group/imports.rs#L313-L349","documentation":"populate_imports_from_linker resolves a function import by fetching it from the exporting instance's exports. If get_function fails at this late stage — after the symbol was already recorded as resolved — the replay diverged from the recorded resolution, indicating an internal inconsistency, so it panics with the failing import name.","triggerScenarios":"create_instance_group/prepare_side_module_from_linker where a recorded function resolution points at an instance (resolved_from) whose exports do not contain import.name() — e.g. wrong instance index in the resolution record, exports changed/overridden between record and population, or a mismatched symbol record type.","commonSituations":"dlopen-style linking where a side module's import resolved to an instance that was later replaced or not instantiated; custom linker forks editing resolution records; symbol names shadowed by env/config imports registered after resolution.","solutions":["Verify the resolution record's resolved_from instance actually exports import.name() (log instance exports at record time).","Ensure instances are created and registered in the same order/indices between resolution recording and population.","Do not mutate linker state or instance exports between the two passes.","Reproduce with a minimal module pair on stock wasmtime and report upstream if it still panics."],"exampleFix":"// before\ninstance.exports.get_function(import.name()).unwrap_or_else(|e| panic!(...))\n// after: re-validate against resolution record, fail as LinkError\nlet func = instance.exports.get_function(import.name())\n    .map_err(|e| LinkError::FunctionResolutionFailed(import.name().to_string(), e))?;","handlingStrategy":"validation","validationCode":"// Before populating, confirm each recorded function resolution is fetchable\nif let Some(rec) = linker_state.symbol_resolution_records.get(&key) {\n    if let Some(idx) = rec.resolved_from() {\n        if let Some(inst) = group.try_instance(idx) {\n            assert!(inst.exports.get_function(import.name()).is_ok(),\n                \"recorded function {} missing from instance {}\", import.name(), idx);\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"// Defensive isolation for custom linker flows:\nlet result = std::panic::catch_unwind(|| group.populate_imports_from_linker(&mut store, &linker_state));\nmatch result {\n    Ok(r) => r,\n    Err(_) => Err(LinkError::FunctionResolutionFailed(import_name)),\n}","preventionTips":["Keep instance indices stable between resolution recording and import population.","Do not replace or recreate instances mid-link; recreate the whole instance group instead.","Log exporting instance's exports at resolution time to detect shadowing/overriding early.","Verify recorded function symbols against a minimal repro on stock wasmtime before forking linker internals."],"tags":["panic","dynamic-linking","linker","wasix","internal-error"],"backgroundTag":"function-resolution-failed","analyzedSha":"8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5","analyzedAt":"2026-09-01T23:06:31.009Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}