Troubleshooting

View Source

The errors you are likely to meet, what they mean and what to do. Every guest failure is {error, #{class, kind, message}}; the kind is the key to look up here. Build problems show up as rebar3 compile output.

The NIF does not load

SymptomCauseFix
wasmtime: no prebuilt library for ...; building from source and then a missing toolno archive for the platform, and git, cmake or cargo is absentinstall them (https://rustup.rs) or point WASMTIME_C_API_DIR at a C API tree
checksum mismatch for wasmtime-...tar.xza corrupt or tampered download; never an unsupported platformdelete _build/wasmtime and retry; if it persists, compare with the upstream checksum
include/ and lib/ differ at compile timeWASMTIME_C_API_DIR mixes headers and a library from different buildsuse one archive
wasmtime_nif.so from an older build after changing WASMTIME_C_API_DIR or WASMTIME_RUNTIME_ONLYthe stamp file says nothing changedrm _build/wasmtime_nif.stamp && rebar3 compile
{error, {load_failed, ...}} on a releasepriv/ missing the .so or, for runtime-only builds, libwasmtime.so/.dylib next to itship priv/ whole; the NIF finds the shared library through an rpath relative to itself

Compile and load

kind or messageMeaningDo
unavailable on compile/1, {wat, _}, serialize/1a runtime-only build has no compilerprecompile on a full build, load with deserialize/1,2; features/0 says what the build can do
compilation settings are not compatible with the native hostthe .cwasm was compiled with other engine settings (fuel, opt_level, target, CPU features)precompile on the same platform with the options you load with; deserialize/2 with #{fuel => true} or the opt_level used; see precompiled
module was compiled with concurrency support but it is not enabled for the hostthe .cwasm came from a tool with different engine defaults (the Wasmtime CLI, another embedding)compile with this library's serialize/1, or the flags scripts/precompile-shims.sh uses
too_many_configurationsmore than 32 distinct compile option sets in this VMreuse option sets; engines are never freed
class => linkan import the module needs is not in imports (or WASI was not granted)check imports/1; give wasi => #{} for WASI programs
unsupported_importthe module imports a memory, table or globalonly function imports can come from Erlang
unsupported_typeexnref in a signature, v128 and references in one signature, or a value that cannot crosssplit the function or keep the value inside the guest

Calls

kindMeaningDo
timeoutthe timeout option expired; the guest was interruptedthe instance is usable again; raise the limit or use call_async
interruptinterrupt/1 was called, or the caller diedexpected
out_of_fuelthe fuel budget ran outmore fuel, or none
fuel_disabledfuel given for a module compiled without fuel => truecompile with fuel
busymemory, globals, tables or refs accessed while the guest runsdo it from a host function (the guest is parked) or when the call returns
reentranta host function called the instance it runs onkeep what you need (a funcref, data) and act after the call returns
stoppedthe instance handle was dropped or instantiation failedkeep a reference to the instance while you use it
wrong_instancea ref() used with another instancerefs belong to the instance that made them
badarity, badargwrong number of arguments, or a value that does not match the type (null for a non-nullable reference, a funcref where an externref is expected, {i31, N} out of range)check exports/1

Host functions

MessageMeaningDo
host function timed outthe Erlang fun did not return within host_timeout (default 30 s)keep host funs short; hand long work to another process; raise host_timeout
host process is gonethe host process diedrestart it before instantiating
host function returned the wrong number of values / a value of the wrong typethe fun's {ok, Results} does not match the import's typereturn exactly the declared results
an exception text in messagethe fun raised; class, reason and stacktrace are in the messagethe instance is still usable

Streams

SymptomCauseDo
await/3 times out on a stdin-reading programthe guest waits for inputsend/2 a line, close/1 to end input
inbox_full16 MB queued and unreadwait for the guest to read, or raise inbox_limit
nothing arrives from a Python scriptstdout is block-bufferedrun with -u or print(..., flush=True)
stdin => stream answers unavailable on a runtime-only buildno priv/shims/<platform>-*.cwasm for the platformrun scripts/precompile-shims.sh on a machine with that architecture

Reading a trap

{error, #{class := trap, kind := unreachable, message := Msg,
          trace := [#{func_index := 3, func_offset := 12, func_name := ~"f", module_name := undefined} | _]}}

trace is innermost first. func_name is undefined when the module has no name section; func_index still identifies the function in wasm-objdump or wasm-tools print. message is Wasmtime's own text and includes the backtrace.

When the VM crashes

A crash inside the NIF is a bug here or in Wasmtime: build with WASMTIME_NIF_SANITIZE=address (see CONTRIBUTING.md) and run the case that crashes. Two aborts are known and guarded against: wasm_valtype_kind on GC types and an engine for a target the library lacks; a new one is worth an issue.