{"record":{"id":"796cd0fc74a73c52","repo":"BoundaryML/baml","slug":"javascript-error-0","errorCode":null,"errorMessage":"JavaScript error: {0:?}","messagePattern":"JavaScript error: (.+?)","errorType":"exception","errorClass":"JwtError","httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/internal/wasm_jwt.rs","lineNumber":25,"sourceCode":"/// problematic for some toolchains to cross-compile to WASM.\n///\n/// At the time of writing, the Vertex provider is the only code in the\n/// runtime that produces JWT's.\nuse base64::{\n    engine::general_purpose::{STANDARD, URL_SAFE_NO_PAD},\n    Engine,\n};\nuse js_sys::{Array, Object, Uint8Array};\nuse serde::{Deserialize, Serialize};\nuse serde_json::json;\nuse thiserror::Error;\nuse wasm_bindgen::JsValue;\nuse wasm_bindgen_futures::JsFuture;\nuse web_sys::{window, CryptoKey, SubtleCrypto};\n\n#[derive(Error, Debug)]\npub enum JwtError {\n    #[error(\"JavaScript error: {0:?}\")]\n    JsError(JsValue),\n    #[error(\"Base64 decode error: {0}\")]\n    Base64Error(#[from] base64::DecodeError),\n    #[error(\"JSON error: {0}\")]\n    JsonError(#[from] serde_json::Error),\n    #[error(\"Missing window object\")]\n    NoWindow,\n    #[error(\"Missing crypto API\")]\n    NoCrypto,\n}\n\nimpl From<JsValue> for JwtError {\n    fn from(err: JsValue) -> Self {\n        JwtError::JsError(err)\n    }\n}\n\npub async fn encode_jwt(","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/internal/wasm_jwt.rs#L7-L43","documentation":"JwtError::JsError in the wasm JWT module wraps a raw wasm_bindgen JsValue produced by any failure in a browser JavaScript API call (e.g. SubtleCrypto.sign/importKey, fetch). The thiserror attribute formats it as 'JavaScript error: {0:?}'. It surfaces when BAML runs in WASM (browser) and a JS-side crypto operation rejects.","triggerScenarios":"Calling the WASM JWT signer where window.crypto.subtle.sign/importKey returns a rejected promise; any web_sys JsFuture that resolves to an Err(JsValue).","commonSituations":"Running in a non-secure context (http://) where SubtleCrypto is unavailable or restricted; browser rejecting the key algorithm parameters; CORS or network failure in underlying fetch; very old browsers without WebCrypto.","solutions":["Log the wrapped JsValue (serde-wasm-bindgen or console) to see the real JS message.","Serve the app over HTTPS so the WebCrypto SubtleCrypto API is available.","Verify the algorithm/parameters passed to importKey/sign are supported by the browser.","Test in a modern browser and confirm window.crypto.subtle exists before calling."],"exampleFix":"// before\nlet sig = JsFuture::from(subtle.sign(&algorithm, &key, &data).unwrap()).await?;\n// after\nmatch subtle.sign(&algorithm, &key, &data) {\n    Ok(p) => JsFuture::from(p).await.map_err(JwtError::JsError),\n    Err(e) => { web_sys::console::error_1(&e); Err(JwtError::JsError(e)) }\n}","handlingStrategy":"try-catch","validationCode":"if (!window.isSecureContext || !window.crypto?.subtle) {\n  throw new Error(\"WebCrypto SubtleCrypto unavailable; JWT signing will fail\");\n}","typeGuard":"function hasSubtleCrypto(w) {\n  return typeof w.crypto?.subtle?.sign === \"function\";\n}","tryCatchPattern":"try {\n  const token = await signJwt(claims);\n} catch (e) {\n  if (String(e).includes(\"JavaScript error\")) {\n    console.error(\"WebCrypto failure:\", e); // inspect wrapped JsValue\n  } else { throw e; }\n}","preventionTips":["Serve over HTTPS so SubtleCrypto is available.","Log wrapped JsValues during development to see underlying JS errors.","Test the WASM JWT path in real target browsers early."],"tags":["wasm","javascript","webcrypto","jwt"],"backgroundTag":"api-request-failed","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}