{"record":{"id":"e4bd8ae2d7a1bafc","repo":"tauri-apps/tauri","slug":"failed-to-read-cli-options","errorCode":null,"errorMessage":"failed to read CLI options","messagePattern":"failed to read CLI options","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri-cli/src/mobile/mod.rs","lineNumber":403,"sourceCode":"            \"ws://{}\",\n            read_to_string(&addr_path).unwrap_or_else(|e| panic!(\n              \"failed to read missing addr file {}: {e}\",\n              addr_path.display()\n            ))\n          )\n          .parse()\n          .unwrap(),\n        )\n        .await\n        .context(\"failed to build WebSocket client\")?;\n      let client: Client = ClientBuilder::default().build_with_tokio(tx, rx);\n      let options: CliOptions = client\n        .request(\"options\", rpc_params![])\n        .await\n        .context(\"failed to request options\")?;\n      Ok::<CliOptions, Error>(options)\n    })\n    .expect(\"failed to read CLI options\");\n\n  for (k, v) in &options.vars {\n    set_var(k, v);\n  }\n  options\n}\n\npub fn get_app(\n  target: Target,\n  config: &TauriConfig,\n  interface: &AppInterface,\n  tauri_dir: &Path,\n) -> App {\n  let identifier = match target {\n    Target::Android => config.identifier.replace('-', \"_\"),\n    #[cfg(target_os = \"macos\")]\n    Target::Ios => config.identifier.replace('_', \"-\"),\n  };","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/tauri-apps/tauri/blob/52e4b6e71d8632a7e648f866c442e287ecddee34/crates/tauri-cli/src/mobile/mod.rs#L385-L421","documentation":"For mobile dev/build, the CLI reads back the CliOptions from the running app's RPC server: it reads the WebSocket address from a temp file named <identifier>-server-addr, connects, and requests \"options\" over JSON-RPC. This expect fires when any step inside the async block returns Err — stale/missing addr file, invalid address, WebSocket connect failure (app not running or unreachable), or a failed/malformed RPC response. Note: a missing addr file has its own panic; this one covers connect/request failures.","triggerScenarios":"Running `tauri android/ios dev` (or a follow-up build) when the on-device app's dev server is not reachable: the app crashed at startup, the tauri RPC plugin is disabled/stripped from the build, the device network blocks the reverse/forwarded connection, or the port/address changed between runs.","commonSituations":"Custom app configs that remove the dev-server plugin; apps that crash before starting the RPC server; firewall/USB-network issues; switching between emulator and physical device with stale state.","solutions":["Confirm the app actually launches and stays alive on the device (`adb logcat` / Xcode console) before the CLI reconnects.","Remove stale state: delete old <identifier>-server-addr files from TMPDIR and regenerate the mobile project if needed (tauri android/ios init).","Check that your tauri.conf.json / Cargo features did not disable the mobile dev-server (tauri dev RPC) component.","Verify device-to-host connectivity (adb reverse / same Wi-Fi) and retry on a clean emulator state.","Update the CLI and tauri crate to matching latest versions."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Verify the app's RPC server is up before the CLI reconnects\nlet addr = std::fs::read_to_string(std::env::temp_dir().join(format!(\"{IDENTIFIER}-server-addr\"))).ok();\nif let Some(a) = addr {\n    // probe the ws address with a short timeout before proceeding\n    assert!(a.starts_with(\"ws://\"), \"stale addr file: {a}\");\n}","typeGuard":null,"tryCatchPattern":"// Retry pattern around tauri mobile dev in scripts\nfor attempt in 1 2; do\n  npx tauri android dev && break\n  adb logcat -d --pid=$(adb shell pidof $APP_ID) | tail -50  # inspect why the app died\n  [ \"$attempt\" -eq 2 ] && exit 1\n  adb uninstall $APP_ID 2>/dev/null || true                 # clean device state\n","preventionTips":["Keep the mobile dev-server (RPC) feature enabled in dev builds; don't strip it in feature flags.","Watch `adb logcat` for early app crashes when mobile dev suddenly fails at the options step.","Clear stale <identifier>-server-addr temp files when switching between devices/emulators."],"tags":["mobile","websocket","json-rpc","dev-server","tauri-cli"],"backgroundTag":"rpc-connection-failed","analyzedSha":"52e4b6e71d8632a7e648f866c442e287ecddee34","analyzedAt":"2026-08-20T13:59:20.734Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}