{"record":{"id":"b86d832d44002e7d","repo":"tauri-apps/tauri","slug":"failed-to-setup-app-e","errorCode":null,"errorMessage":"Failed to setup app: {e}","messagePattern":"Failed to setup app: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri/src/app.rs","lineNumber":1431,"sourceCode":"  /// ```\n  pub fn run_return<F: FnMut(&AppHandle<R>, RunEvent) + 'static>(mut self, callback: F) -> i32 {\n    self.handle.event_loop.lock().unwrap().main_thread_id = std::thread::current().id();\n\n    self\n      .runtime\n      .take()\n      .unwrap()\n      .run_return(self.make_run_event_loop_callback(callback))\n  }\n\n  fn make_run_event_loop_callback<F: FnMut(&AppHandle<R>, RunEvent) + 'static>(\n    mut self,\n    mut callback: F,\n  ) -> impl FnMut(RuntimeRunEvent<EventLoopMessage>) {\n    move |event| match event {\n      RuntimeRunEvent::Ready => {\n        if let Err(e) = setup(&mut self) {\n          panic!(\"Failed to setup app: {e}\");\n        }\n        let event = on_event_loop_event(self.handle(), RuntimeRunEvent::Ready, self.manager());\n        callback(self.handle(), event);\n      }\n      RuntimeRunEvent::Exit => {\n        let event = on_event_loop_event(self.handle(), RuntimeRunEvent::Exit, self.manager());\n        callback(self.handle(), event);\n        self.cleanup_before_exit();\n        if self.manager.restart_on_exit.load(atomic::Ordering::Relaxed) {\n          crate::process::restart(&self.env());\n        }\n      }\n      _ => {\n        let event = on_event_loop_event(self.handle(), event, self.manager());\n        callback(self.handle(), event);\n      }\n    }\n  }","sourceCodeStart":1413,"sourceCodeEnd":1449,"githubUrl":"https://github.com/tauri-apps/tauri/blob/460ec35447493200d64290dd7f015d5a91d0fd58/crates/tauri/src/app.rs#L1413-L1449","documentation":"When the app's event loop fires `Ready`, Tauri runs the user's `setup` hook. If that hook returns an error, the app panics with this message instead of continuing to run, because a failed setup leaves the app in an unusable state. The original error is embedded in `{e}`.","triggerScenarios":"The closure returned by `Builder::build(...).run(callback)` receives `RuntimeRunEvent::Ready` and calls `setup(&mut self)`, which invokes the developer's `.setup(|app| ...)` hook; any `Err` returned from that hook (or from internal setup like plugin initialization, state management, or window creation) triggers the panic.","commonSituations":"A plugin fails to initialize during `.plugin()` registration; the setup hook returns Err after a failed file/db open; creating a window/webview with an invalid URL or label inside setup; missing single-instance resources in dev.","solutions":["Read the embedded `{e}` — it names the real cause (plugin init failure, window creation error, etc.) and fix that root issue.","Return `Ok(())` from your `.setup()` hook only after validating fallible operations; handle recoverable errors inside the hook instead of propagating them.","If a plugin's `.plugin()` call fails, verify the plugin's runtime requirements (config in tauri.conf.json, external binaries, permissions).","Test setup logic in isolation (e.g. open the DB/file before `tauri::Builder::run`) so failures surface with clearer errors."],"exampleFix":"// before\n.setup(|app| {\n  let win = WebviewWindowBuilder::new(app, \"main\", WebviewUrl::App(\"/\".into())).build()?;\n  Ok(())\n})\n// after\n.setup(|app| {\n  match WebviewWindowBuilder::new(app, \"main\", WebviewUrl::App(\"/\".into())).build() {\n    Ok(_) => Ok(()),\n    Err(e) => { eprintln!(\"window setup failed: {e}\"); Ok(()) } // or fix the root cause\n  }\n})","handlingStrategy":"try-catch","validationCode":"// validate fallible resources before app.run\nlet db = Database::open().expect(\"db\"); // fail early with a clear message, not inside setup","typeGuard":null,"tryCatchPattern":".setup(|app| {\n  if let Err(e) = risky_initialization() {\n    eprintln!(\"setup warning: {e}\"); // recover or decide\n    // return Ok(()) to keep running, or propagate to fail fast\n  }\n  Ok(())\n})\n// Note: errors returned from setup panic in run(); handle recoverable ones inside the hook","preventionTips":["Keep the setup hook minimal; do heavy fallible work before Builder::run","Always read the embedded `{e}` to find the true failure (plugin, window, state)","Verify plugin config in tauri.conf.json matches plugin requirements","Test window/webview creation parameters (labels, URLs) before shipping"],"tags":["setup","panic","app-lifecycle","plugins"],"backgroundTag":"invalid-state-transition","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"}