{"record":{"id":"ea35be3d9ec47ca2","repo":"slint-ui/slint","slug":"err","errorCode":null,"errorMessage":"{err}","messagePattern":"\\{err\\}","errorType":"exception","errorClass":"js_sys::Error","httpStatus":null,"severity":"error","filePath":"tools/lsp/wasm_main.rs","lineNumber":331,"sourceCode":"                    &ctx.server_notifier,\n                    uri,\n                    version,\n                    diagnostics,\n                );\n            }\n            M::ShowDocument { file, selection, .. } => {\n                let sn = ctx.server_notifier.clone();\n                wasm_bindgen_futures::spawn_local(async move {\n                    crate::lsp_to_editor::send_show_document_to_editor(sn, file, selection, true)\n                        .await\n                });\n            }\n            M::PreviewTypeChanged { target } => {\n                ctx.session\n                    .primary_preview()\n                    .to_preview\n                    .set_local_target(target)\n                    .map_err(|err| js_sys::Error::new(&format!(\"{err}\")))?;\n            }\n            M::RequestState { files, settings } => {\n                crate::language::send_requested_state_to_preview(&ctx, &files, &settings);\n            }\n            M::UpdateUserSettings { name, contents } => {\n                crate::language::store_user_settings(&name, &contents);\n            }\n            M::SendWorkspaceEdit { label, edit } => {\n                forward_workspace_edit(ctx.server_notifier.clone(), label, Ok(edit));\n            }\n            M::SendShowMessage { message } => {\n                let _ = ctx\n                    .server_notifier\n                    .send_notification::<lsp_types::notification::ShowMessage>(message);\n            }\n            M::TelemetryEvent(object) => {\n                let _ = ctx\n                    .server_notifier","sourceCodeStart":313,"sourceCodeEnd":349,"githubUrl":"https://github.com/slint-ui/slint/blob/bb937076de3f7919766c1f25e2e969367cf77e9a/tools/lsp/wasm_main.rs#L313-L349","documentation":"In tools/lsp/wasm_main.rs, process_preview_to_lsp_message handles the PreviewTypeChanged message by calling set_local_target on the primary preview; on failure the returned error is converted into a js_sys::Error whose message is just the Display of the err (\"{err}\") and propagated with `?` to JS. The browser sees a generic JS Error carrying the stringified internal failure (e.g. an invalid or unsupported preview target).","triggerScenarios":"Calling the WASM LSP entry with message M::PreviewTypeChanged whose target value is rejected by set_local_target (e.g. a target not supported in the current environment/build), causing map_err to wrap it in js_sys::Error and early-return from the public function.","commonSituations":"A frontend (SlintPad / VS Code web extension) switches preview type to a target unavailable in the WASM build (e.g. a renderer or platform target compiled out), so the local target cannot be applied.","solutions":["Check the preview target value sent from JS is one the WASM build supports before sending PreviewTypeChanged.","Rebuild the WASM bundle with the required preview target feature enabled, or restrict the UI's target selector to supported values.","In JS, wrap the call in try/catch and inspect error.message (the stringified err) to surface which target failed."],"exampleFix":"// before (JS)\nlsp.setPreviewTarget(\"winit\");\n// after (JS)\ntry {\n  lsp.setPreviewTarget(\"wasm\" /* supported target */);\n} catch (e) {\n  console.error(\"Preview target change failed:\", e.message);\n}","handlingStrategy":"try-catch","validationCode":"// JS side, before sending the message\nconst supported = [\"wasm\", \"browser\"]; // targets compiled into this WASM build\nif (!supported.includes(target)) {\n  throw new Error(`Preview target \"${target}\" not supported by this build`);\n}\nlsp.processMessage({ PreviewTypeChanged: { target } });","typeGuard":"function isSupportedTarget(t) { return typeof t === \"string\" && SUPPORTED_TARGETS.includes(t); }","tryCatchPattern":"try {\n  processPreviewToLspMessage({ PreviewTypeChanged: { target } });\n} catch (e) {\n  console.error(\"set_local_target failed:\", e.message); // message is the stringified internal err\n}","preventionTips":["Keep the JS target selector in sync with the features compiled into the WASM bundle.","Validate target strings against the Rust enum's serialized names before sending across the wasm boundary.","Always wrap wasm-boundary calls in try/catch since Rust errors surface as js_sys::Error rejections."],"tags":["wasm","javascript","lsp","live-preview"],"backgroundTag":"invalid-enum-value","analyzedSha":"bb937076de3f7919766c1f25e2e969367cf77e9a","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}