{"record":{"id":"fbe69291c1bd70f6","repo":"BoundaryML/baml","slug":"js-callback-error-name-message","errorCode":null,"errorMessage":"JS callback error: {name}: {message}","messagePattern":"JS callback error: (.+?): (.+?)","errorType":"exception","errorClass":"RuntimeCallbackError","httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/types/js_callback_provider.rs","lineNumber":35,"sourceCode":"pub struct JsCallbackError {\n    pub name: String,\n    pub message: String,\n}\n\n#[derive(Debug, Error, Clone)]\n/// For baml-src-reader and aws-cred-provider, provide a statically defined type which is Send + Sync\n/// anyhow::Error is not Send + Sync, so it's convoluted to use it in this callback context\npub enum RuntimeCallbackError {\n    #[error(\"Failed to send cred request across WASM bridge: {0}\")]\n    SendError(String),\n\n    #[error(\"Failed to recv cred response across WASM bridge: {0}\")]\n    RecvError(String),\n\n    #[error(\"Type error in JS callback: {0}\")]\n    JsCallbackTypeError(String),\n\n    #[error(\"JS callback error: {name}: {message}\")]\n    JsCallbackRuntimeError { name: String, message: String },\n\n    #[error(\"BAML internal error - credential provider bridges not initialized\")]\n    NoCredProviderBridge,\n}\n\nstatic_assertions::assert_impl_all!(RuntimeCallbackError: Send, Sync);\n\npub type RuntimeCallbackResult<T> = Result<T, RuntimeCallbackError>;\n\nstatic JS_CALLBACK_PROVIDER_SINGLETON: OnceLock<JsCallbackProvider> = OnceLock::new();\n\npub fn get_js_callback_provider() -> Result<&'static JsCallbackProvider, RuntimeCallbackError> {\n    JS_CALLBACK_PROVIDER_SINGLETON\n        .get()\n        .ok_or(RuntimeCallbackError::NoCredProviderBridge)\n}\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/types/js_callback_provider.rs#L17-L53","documentation":"RuntimeCallbackError::JsCallbackRuntimeError carries an actual exception thrown by the JS credential provider callback. The bridge deserializes the `error` branch of JsCallbackResult (js_callback_provider.rs:11-12, 17-20) into `name` and `message` fields, so the JS-side error type name and message are preserved across the WASM boundary and rethrown in Rust.","triggerScenarios":"The JS-side AWS/GCP credential provider throws or its promise rejects; the bridge serializes it as `{\"error\": {\"name\", \"message\"}}`, and `aws_req`/`gcp_req` return it via the `Ok(Err(e))` branch (js_callback_provider.rs:107-110 and 130-133) as `JsCallbackRuntimeError { name, message }`.","commonSituations":"AWS `fromIni` fails because the profile is missing from ~/.aws/credentials, the container has no AWS credentials/env configured (`CredentialsProviderError`), GCP auth fails due to missing GOOGLE_APPLICATION_CREDENTIALS, or the custom JS provider itself throws on network/permission errors.","solutions":["Read `name` and `message` in the error to identify the JS-side failure (e.g. missing AWS profile, expired token) and fix that root cause.","Verify AWS credentials exist: check ~/.aws/credentials for the requested profile, or set AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY/AWS_SESSION_TOKEN env vars.","For GCP, ensure GOOGLE_APPLICATION_CREDENTIALS points to a valid service-account JSON key.","If using a custom provider, add try/catch and logging in the JS callback to surface clearer error messages."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-check AWS/GCP credentials on the JS side before invoking BAML\ntry { await fromIni({ profile: 'my-profile' })(); } catch (e) { console.error('AWS profile unavailable:', e.message); }\nif (!process.env.GOOGLE_APPLICATION_CREDENTIALS && !process.env.GCP_ACCESS_TOKEN) console.warn('GCP credentials not configured');","typeGuard":null,"tryCatchPattern":"// inspect the propagated JS error name/message\ntry {\n  const result = await b.GenerateSummary(input);\n} catch (e) {\n  if (String(e).startsWith('JS callback error:')) {\n    console.error('Credential provider failed:', e.message); // e.g. 'CredentialsProviderError: Could not load credentials'\n    // fall back to alternate credentials or fail fast with a clear message\n  } else { throw e; }\n}","preventionTips":["Verify the AWS profile exists in ~/.aws/credentials or set AWS_* env vars in the deployment","Set GOOGLE_APPLICATION_CREDENTIALS for GCP workloads","Wrap your custom JS credential provider in try/catch with descriptive errors"],"tags":["wasm","javascript","credentials","aws","gcp"],"backgroundTag":"missing-credentials","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"}