{"record":{"id":"440b60c9ebeb2218","repo":"BoundaryML/baml","slug":"type-error-in-js-callback-0","errorCode":null,"errorMessage":"Type error in JS callback: {0}","messagePattern":"Type error in JS callback: (.+?)","errorType":"exception","errorClass":"RuntimeCallbackError","httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/types/js_callback_provider.rs","lineNumber":32,"sourceCode":"\n#[derive(Debug, serde::Deserialize, Eq, PartialEq)]\n/// Deserialization helper for js_callback_bridge; declared here to enable deserialization unit testing.\npub 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()","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/types/js_callback_provider.rs#L14-L50","documentation":"RuntimeCallbackError::JsCallbackTypeError is raised when the value returned from the JS credential callback cannot be correctly shaped/typed when crossing the WASM bridge - i.e. the JS side returned something that does not deserialize into the expected credential result envelope (JsCallbackResult<T>). It is a data-shape mismatch between the JS provider's return value and the Rust expected type, not a thrown JS exception.","triggerScenarios":"The JS/WASM bridge deserializes the callback response via JsCallbackResult<T>/serde (js_callback_provider.rs:8-20) and the returned object fails type checking - e.g. missing `ok`/`error` envelope keys, wrong field names, or wrong primitive types - producing a type error surfaced as `JsCallbackTypeError(String)`.","commonSituations":"A custom JS AWS credential provider returns credentials with misspelled camelCase fields (e.g. `accessKey` instead of `accessKeyId`), returns a raw credential object instead of the expected envelope, or returns undefined/null when the provider fails silently.","solutions":["Make the JS credential callback return an object matching AwsCredentialIdentity (`accessKeyId`, `secretAccessKey`, optional `sessionToken`) or the documented ok/error envelope.","Log the raw value returned by your JS provider and compare it field-by-field with the expected camelCase schema.","Check that your provider resolves with the credential object rather than returning undefined (e.g. an async function without a return).","If wrapping the Smithy provider, verify the SDK version's AwsCredentialIdentity shape matches what BAML's bridge expects."],"exampleFix":"// before: wrong field names in JS provider return\nasync () => ({ accessKey: 'AKIA...', secret: '...' });\n\n// after: match the expected AwsCredentialIdentity shape\nasync () => ({ accessKeyId: 'AKIA...', secretAccessKey: '...', sessionToken: undefined });","handlingStrategy":"validation","validationCode":"// validate the JS provider's return shape before registering it\nfunction isValidAwsCred(c) {\n  return c && typeof c.accessKeyId === 'string' && typeof c.secretAccessKey === 'string';\n}\nconst provider = async (args) => {\n  const cred = await myProvider(args);\n  if (!isValidAwsCred(cred)) throw new Error('Provider returned invalid credential shape');\n  return cred;\n};","typeGuard":"function isAwsCredentialIdentity(v) {\n  return (\n    typeof v === 'object' && v !== null &&\n    typeof v.accessKeyId === 'string' &&\n    typeof v.secretAccessKey === 'string' &&\n    (v.sessionToken === undefined || typeof v.sessionToken === 'string')\n  );\n}","tryCatchPattern":null,"preventionTips":["Return camelCase fields exactly matching AwsCredentialIdentity (accessKeyId, secretAccessKey)","Always resolve the provider promise with a credential object, never undefined","Unit-test your JS provider's return value against the expected shape"],"tags":["wasm","type-mismatch","javascript","credentials","serialization"],"backgroundTag":"type-mismatch","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"}