{"record":{"id":"2360b69083e9aea9","repo":"wasmerio/wasmer","slug":"env-indirect-function-table-import-for-wasm-c-ap","errorCode":null,"errorMessage":"env.__indirect_function_table import for Wasm C API module is not a table","messagePattern":"env\\.__indirect_function_table import for Wasm C API module is not a table","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"lib/c-api-imports/src/lib.rs","lineNumber":168,"sourceCode":"        register_wasm_c_api_imports(store, &func_env, io);\n\n        if let Some(memory_type) = self.imported_memory_type {\n            if let Some(existing) = io.get_export(\"env\", \"memory\") {\n                let Extern::Memory(memory) = existing else {\n                    bail!(\"env.memory import for Wasm C API module is not a memory\");\n                };\n                self.set_memory(store, &memory)?;\n            } else {\n                let memory = Memory::new(&mut *store, memory_type)?;\n                io.define(\"env\", \"memory\", memory.clone());\n                self.set_memory(store, &memory)?;\n            }\n        }\n\n        if let Some(table_type) = self.imported_table_type {\n            if let Some(existing) = io.get_export(\"env\", \"__indirect_function_table\") {\n                let Extern::Table(table) = existing else {\n                    bail!(\n                        \"env.__indirect_function_table import for Wasm C API module is not a table\"\n                    );\n                };\n                self.set_table(store, &table)?;\n            } else {\n                let table = Table::new(&mut *store, table_type, Value::FuncRef(None))?;\n                io.define(\"env\", \"__indirect_function_table\", table.clone());\n                self.set_table(store, &table)?;\n            }\n        }\n\n        Ok(())\n    }\n\n    fn set_memory(&self, store: &mut StoreMut<'_>, memory: &Memory) -> Result<()> {\n        let Some(func_env) = self.func_env()? else {\n            return Ok(());\n        };","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/wasmerio/wasmer/blob/8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5/lib/c-api-imports/src/lib.rs#L150-L186","documentation":"Analogous to the memory case: if the module needs the imported table `env.__indirect_function_table` and the imports already contain an export of that name which is not an Extern::Table, register_imports bails. The C API layer stores the Table handle in its state and cannot substitute another extern type.","triggerScenarios":"Instantiating a Wasm C API module requiring __indirect_function_table while the Imports set defines \"env\" \"__indirect_function_table\" as a memory/function/global, via add_imports.","commonSituations":"Custom table assigned under the standard C API table name but with the wrong extern type; collision with an existing host export of the same name; copy-pasted import wiring between modules.","solutions":["Define \"env\" \"__indirect_function_table\" as an actual Table (initialized with Value::FuncRef(None))","Remove or rename the conflicting non-table export","Omit the pre-defined import so Wasmer creates the table from the module's declared table type"],"exampleFix":"// before\nio.define(\"env\", \"__indirect_function_table\", my_memory.clone());\n// after\nlet table = Table::new(&mut store, table_type, Value::FuncRef(None))?;\nio.define(\"env\", \"__indirect_function_table\", table);","handlingStrategy":"validation","validationCode":"if let Some(e) = io.get_export(\"env\", \"__indirect_function_table\") {\n    if !matches!(e, Extern::Table(_)) {\n        return Err(\"__indirect_function_table is defined but not a Table\");\n    }\n}","typeGuard":"fn is_table_export(e: Option<&Extern>) -> bool {\n    matches!(e, Some(Extern::Table(_)))\n}","tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"is not a table\") => fix_env_table_import_and_retry(),\n    other => other?,\n}","preventionTips":["Define env.__indirect_function_table only with Table instances","Do not repurpose the C API standard table name for other exports","Let Wasmer create the table when your module declares one instead of pre-defining it"],"tags":["wasm","c-api","imports","table","type-mismatch"],"backgroundTag":"import-type-mismatch","analyzedSha":"8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5","analyzedAt":"2026-09-01T23:06:31.009Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}