windmill-labs/windmill · error

fwrite is not supported

Error message

fwrite is not supported

What it means

fwrite() is a panic stub in wasm_libc.rs ("fwrite is not supported"). Writing raw blocks to a FILE* is unsupported because no real streams exist in the WASM host. Any call — including printf-family internals routed through fwrite — aborts execution.

Source

Thrown at backend/parsers/windmill-parser-csharp/src/wasm_libc.rs:180

#[no_mangle]
pub unsafe extern "C" fn fdopen(_fd: c_int, _mode: *const c_void) -> *mut c_void {
    panic!("fdopen is not supported");
}

#[no_mangle]
pub unsafe extern "C" fn fclose(_file: *mut c_void) -> c_int {
    panic!("fclose is not supported");
}

#[no_mangle]
pub unsafe extern "C" fn fwrite(
    _ptr: *const c_void,
    _size: usize,
    _nmemb: usize,
    _stream: *mut c_void,
) -> usize {
    panic!("fwrite is not supported");
}

#[no_mangle]
pub unsafe extern "C" fn vsnprintf(
    _buf: *mut c_char,
    _size: usize,
    _format: *const c_char,
    _args: ...
) -> c_int {
    panic!("vsnprintf is not supported");
}

#[no_mangle]
pub extern "C" fn clock_gettime(ptr: usize, new_size: usize) {
    panic!("asdasd");
}

// int snprintf( char* restrict buffer, size_t bufsz, const char* restrict format, ... );

View on GitHub (pinned to e474e8803c)

Solutions

  1. Disable the runtime feature that performs stream writes in WASM.
  2. Route buffered output to the console_log shim or an in-memory ring buffer instead.
  3. Implement fwrite in wasm_libc.rs forwarding to a supported sink (write length-checked bytes to console).
  4. Rebuild the native component with stdio removed.

Example fix

// before
fwrite(buf, 1, len, stdout);
// after
console_log!("{}", core::str::from_utf8(&buf[..len]).unwrap_or("<binary>"));
Defensive patterns

Strategy: try-catch

Validate before calling

// Intercept raw stream writes before executing in the wasm host:
if (isWasmHost && writesToStreams(code)) {
  throw new Error("fwrite-style stream output unsupported in the wasm C# parser.");
}

Try / catch

try {
  runInWasmParser(code);
} catch (e) {
  if (String(e?.message ?? e).includes("fwrite is not supported")) {
    console.warn("fwrite is unsupported in wasm; buffer output or route it to the console shim.");
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: The runtime or native code calls fwrite(ptr, size, nmemb, stream) to write bytes to stdout/stderr or a file; printf-family implementations that flush via fwrite.

Common situations: puts/printf implemented on top of fwrite in a vendored libc; binary dumps to streams; mono diagnostic paths writing buffers to stderr.

Related errors


AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03). Data as JSON: /api/errors/d12d29dacb637eb7. Report an issue: GitHub.