{"record":{"id":"f4183e91ebe112f0","repo":"tauri-apps/tauri","slug":"unable-to-serialize-response-error-string-to-json","errorCode":null,"errorMessage":"unable to serialize response error string to json","messagePattern":"unable to serialize response error string to json","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri/src/ipc/protocol.rs","lineNumber":333,"sourceCode":"        request,\n        Box::new(move |webview, cmd, response, callback, error| {\n          use crate::ipc::Channel;\n\n          #[cfg(feature = \"tracing\")]\n          let _respond_span = tracing::trace_span!(\n            parent: &request_span,\n            \"ipc::request::respond\"\n          )\n          .entered();\n\n          fn responder_eval<R: Runtime>(\n            webview: &crate::Webview<R>,\n            js: crate::Result<String>,\n            error: CallbackFn,\n          ) {\n            let eval_js = js.unwrap_or_else(|e| {\n              crate::ipc::format_callback::format(error, &e.to_string())\n                .expect(\"unable to serialize response error string to json\")\n            });\n            let _ = webview.eval(eval_js);\n          }\n\n          let can_use_channel_for_response = cmd != crate::ipc::channel::FETCH_CHANNEL_DATA_COMMAND\n            && !options.custom_protocol_ipc_blocked;\n\n          #[cfg(feature = \"tracing\")]\n          let mime_type = match &response {\n            InvokeResponse::Ok(InvokeResponseBody::Json(_)) => mime::APPLICATION_JSON,\n            InvokeResponse::Ok(InvokeResponseBody::Raw(_)) => mime::APPLICATION_OCTET_STREAM,\n            InvokeResponse::Err(_) => mime::APPLICATION_JSON,\n          };\n\n          #[cfg(feature = \"tracing\")]\n          let _response_span = match &response {\n            InvokeResponse::Ok(InvokeResponseBody::Json(v)) => tracing::trace_span!(\n              \"ipc::request::response\",","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/tauri-apps/tauri/blob/460ec35447493200d64290dd7f015d5a91d0fd58/crates/tauri/src/ipc/protocol.rs#L315-L351","documentation":"When an IPC command returns an error and the response must be delivered back to the webview via `window.eval`, Tauri formats the error string into the callback JS. `format_callback` uses serde to JSON-encode the message; if that fails this panic fires, which should be impossible for a plain string.","triggerScenarios":"An invoke handler returns `Err(e)` whose `Display` output is serialized via `format_callback::format`, and serde_json serialization of the string unexpectedly fails.","commonSituations":"Extremely rare in practice; seen when custom `RuntimeError`/error types contribute control characters or when running patched/old tauri versions where the callback formatting was fragile.","solutions":["Return simple, well-formed string errors from commands (avoid exotic characters in error messages).","Upgrade tauri; modern versions handle callback formatting without panicking.","Prefer the channel-based response path (or `Result<T, E>` with `Serialize` errors) which bypasses this eval formatting.","If reproducible, log the failing error string and file an issue — it indicates a serde bug or patched dependency."],"exampleFix":"// before\nErr(format!(\"failed: {:?}\", raw_bytes)) // may contain invalid content\n// after\nErr(format!(\"failed: {}\", String::from_utf8_lossy(&raw_bytes)))","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// In commands, return clean serializable errors\n#[tauri::command]\nfn run() -> Result<(), String> {\n  inner().map_err(|e| e.to_string()) // plain UTF-8 string, no exotic bytes\n}","preventionTips":["Return simple string or typed Serialize errors from commands","Strip binary/control data out of error messages","Prefer channel-based responses for large payloads"],"tags":["ipc","serde","callback","panic"],"backgroundTag":"json-serialization-failed","analyzedSha":"460ec35447493200d64290dd7f015d5a91d0fd58","analyzedAt":"2026-09-18T23:55:51.277Z","contentChangedAt":"2026-09-18T23:55:51.277Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}