{"record":{"id":"09edd0e18e356cee","repo":"windmill-labs/windmill","slug":"eval-sync-is-only-available-in-wasm32","errorCode":null,"errorMessage":"eval_sync is only available in wasm32","messagePattern":"eval_sync is only available in wasm32","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/parsers/windmill-parser-ts/src/lib.rs","lineNumber":1263,"sourceCode":"#[cfg(target_arch = \"wasm32\")]\n#[wasm_bindgen]\nextern \"C\" {\n    pub fn eval(s: &str) -> JsValue;\n    pub fn alert(s: &str);\n    #[wasm_bindgen(js_namespace = console)]\n    fn log(s: &str);\n\n}\n\n#[cfg(target_arch = \"wasm32\")]\npub fn eval_sync(code: &str) -> Result<serde_json::Value, String> {\n    serde_wasm_bindgen::from_value(eval(format!(\"let x = {}; x\", code).as_str()))\n        .map_err(|err| format!(\"Cannot deserialize value: {:?}\", err))\n}\n\n#[cfg(not(target_arch = \"wasm32\"))]\npub fn eval_sync(_code: &str) -> Result<serde_json::Value, String> {\n    panic!(\"eval_sync is only available in wasm32\")\n}\n","sourceCodeStart":1245,"sourceCodeEnd":1265,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/parsers/windmill-parser-ts/src/lib.rs#L1245-L1265","documentation":"`eval_sync` in windmill-parser-ts only exists when compiled for `wasm32`; the non-wasm fallback is a hard `panic!`. Code calling `eval_sync` outside the WASM runtime (e.g. unit tests or native builds of the TS parser crate) aborts, because JS evaluation depends on the browser/wasm bindgen `eval` function.","triggerScenarios":"Calling `eval_sync` from a build without `target_arch = \"wasm32\"` — typically native unit tests, CLI tooling, or a non-wasm consumer of the parser crate.","commonSituations":"Running the parser crate's tests natively with a test that hits eval_sync; embedding windmill-parser-ts in a native Rust binary instead of the WASM module.","solutions":["Run the code inside the wasm32 target (the intended deployment: compile to WASM and call from JS)","Gate the test/caller with #[cfg(target_arch = \"wasm32\")] so it is skipped on native builds","Refactor the caller to accept a pre-computed value instead of evaluating JS synchronously on native targets"],"exampleFix":"// before\n#[test]\nfn evals() { assert_eq!(eval_sync(\"1+1\").unwrap(), 2); }\n// after\n#[cfg(target_arch = \"wasm32\")]\n#[test]\nfn evals() { assert_eq!(eval_sync(\"1+1\").unwrap(), 2); }","handlingStrategy":"type-guard","validationCode":"// Rust caller: only call eval_sync on wasm builds\n#[cfg(target_arch = \"wasm32\")]\nlet v = eval_sync(code)?;\n#[cfg(not(target_arch = \"wasm32\"))]\nlet v: serde_json::Value = return Err(\"eval_sync requires the wasm32 parser build\".into());","typeGuard":"fn eval_sync_available() -> bool {\n    cfg!(target_arch = \"wasm32\")\n}\n// guard: if !eval_sync_available() { skip/defer the eval path }","tryCatchPattern":"std::panic::catch_unwind(|| eval_sync(code)).unwrap_or_else(|_|\n    Err(\"eval_sync is only available in wasm32; use the wasm build of windmill-parser-ts\".to_string()))","preventionTips":["Never call eval_sync from native tests or native binaries","Gate eval-dependent tests with #[cfg(target_arch = \"wasm32\")]","Run parser tests via wasm-bindgen-test instead of cargo test natively"],"tags":["wasm","typescript","rust","compile-target"],"backgroundTag":"wrong-compile-target","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}