{"record":{"id":"7b01b52d68606817","repo":"BigPizzaV3/CodexPlusPlus","slug":"native-menu-localizer-threw-exception","errorCode":null,"errorMessage":"native menu localizer threw: {exception}","messagePattern":"native menu localizer threw: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/native_menu.rs","lineNumber":197,"sourceCode":"                    .web_socket_debugger_url\n                    .as_deref()\n                    .is_some_and(|url| !url.is_empty())\n            })\n        })\n        .context(\"No Electron main-process inspector target found\")?;\n    let websocket_url = target\n        .web_socket_debugger_url\n        .as_deref()\n        .context(\"selected inspector target has no websocket URL\")?;\n    let script = native_menu_localizer_script()?;\n    let result = crate::bridge::evaluate_script_with_await_promise(websocket_url, &script, true)\n        .await\n        .context(\"failed to evaluate native menu localizer\")?;\n    if let Some(exception) = result\n        .get(\"result\")\n        .and_then(|value| value.get(\"exceptionDetails\"))\n    {\n        bail!(\"native menu localizer threw: {exception}\");\n    }\n    let _ = crate::diagnostic_log::append_diagnostic_log(\n        \"native_menu.localization_installed\",\n        json!({\n            \"inspector_port\": inspector_port,\n            \"target_type\": target.target_type,\n            \"target_title\": target.title,\n            \"result\": result\n        }),\n    );\n    Ok(())\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    #[test]","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/native_menu.rs#L179-L215","documentation":"try_install_native_menu_localizer evaluates a JavaScript localizer in the native menu context via the inspector (CDP). If the evaluation result contains exceptionDetails, the injected script threw, and the raw exception JSON is surfaced as the error message. This indicates the localization script itself failed at runtime inside the native menu environment.","triggerScenarios":"Calling install_native_menu_localizer when the evaluated script throws — e.g. the menu DOM/bridge shape differs from what the script expects, the context isn't ready, or a referenced API is undefined in that runtime.","commonSituations":"App version changed the native menu structure so the localizer's selectors/APIs no longer exist; evaluating too early before the menu context loads; inspector port pointing at the wrong target type.","solutions":["Read the exceptionDetails in the message (it includes exception text and stack) to identify the failing script line.","Ensure the menu/webview context is fully loaded before installing the localizer (retry after target ready).","Update the localizer script to match the current native menu DOM/API of the app version.","Verify inspector_port and target_type point at the correct menu target, then retry."],"exampleFix":"// before\ninstall_native_menu_localizer(port).await?; // throws if script throws\n// after\nmatch install_native_menu_localizer(port).await {\n    Ok(()) => {},\n    Err(e) => { log::warn!(\"localizer failed, retrying after load: {e}\");\n                wait_for_menu_ready(port).await?;\n                install_native_menu_localizer(port).await?; }\n}","handlingStrategy":"try-catch","validationCode":"// Pre-check: ensure the inspector target is reachable before evaluating\nlet reachable = tcp_connect(inspector_port).is_ok();","typeGuard":null,"tryCatchPattern":"match install_native_menu_localizer(port).await {\n    Ok(()) => {},\n    Err(e) if e.to_string().starts_with(\"native menu localizer threw\") => {\n        diagnostic_log(\"localizer_exception\", &e.to_string());\n        // fall back to default (unlocalized) menu\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Keep the localizer script in sync with the app's native menu structure","Wait for the menu target/context to be ready before evaluating","Log exceptionDetails with stack for every failure","Pin the script version to the app version it was written for","Test the localizer against each supported app version in CI"],"tags":["native-menu","javascript","localization","runtime-exception"],"backgroundTag":"internal-invariant-violation","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}