{"record":{"id":"d87ecde17e722b06","repo":"linebender/druid","slug":"there-is-no-globally-active-application","errorCode":null,"errorMessage":"There is no globally active Application","messagePattern":"There is no globally active Application","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"druid-shell/src/application.rs","lineNumber":98,"sourceCode":"    /// Get the current globally active `Application`.\n    ///\n    /// A globally active `Application` exists\n    /// after [`new`] is called and until [`run`] returns.\n    ///\n    /// # Panics\n    ///\n    /// Panics if there is no globally active `Application`.\n    /// For a non-panicking function use [`try_global`].\n    ///\n    /// This function will also panic if called from a non-main thread.\n    ///\n    /// [`new`]: #method.new\n    /// [`run`]: #method.run\n    /// [`try_global`]: #method.try_global\n    #[inline]\n    pub fn global() -> Application {\n        // Main thread assertion takes place in try_global()\n        Application::try_global().expect(\"There is no globally active Application\")\n    }\n\n    /// Get the current globally active `Application`.\n    ///\n    /// A globally active `Application` exists\n    /// after [`new`] is called and until [`run`] returns.\n    ///\n    /// # Panics\n    ///\n    /// Panics if called from a non-main thread.\n    ///\n    /// [`new`]: #method.new\n    /// [`run`]: #method.run\n    pub fn try_global() -> Option<Application> {\n        util::assert_main_thread_or_main_unclaimed();\n        GLOBAL_APP.with(|global_app| global_app.borrow().clone())\n    }\n","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/linebender/druid/blob/0f8b1195e4e073f9597f2865299c3d18f8e4005f/druid-shell/src/application.rs#L80-L116","documentation":"Application::global() returns the process-wide active druid-shell Application and panics (via expect) when none exists. A global Application only exists between Application::new() and the end of Application::run(); calling global() outside that window panics with this message instead of returning Result.","triggerScenarios":"Calling Application::global() before ever calling Application::new(); calling it after run() has returned; calling it from a test or helper where no Application was initialized on the main thread (try_global also asserts main thread); constructing windows/headless contexts before app startup.","commonSituations":"Unit tests touching WindowBuilder or clipboard without app setup; background threads created before run(); utility binaries that build windows without an Application; calling global() in static initializers.","solutions":["Call `Application::new()` (on the main thread) before any code path that uses Application::global().","Use `Application::try_global()` and handle None instead of panicking, when global availability is uncertain.","In tests, initialize an Application in the test setup, or avoid APIs that require a global app (use mock abstractions).","Ensure all window/clipboard work happens between new() and run() returning, on the main thread."],"exampleFix":"// before\nfn open_window() -> WindowHandle {\n    WindowBuilder::new(Application::global()).build().unwrap()\n}\n\n// after\nfn open_window(app: &Application) -> Result<WindowHandle, Error> {\n    WindowBuilder::new(app.clone()).build()\n}\n// or: Application::try_global().ok_or_else(|| anyhow!(\"no active application\"))?","handlingStrategy":"fallback","validationCode":"let app = druid_shell::Application::try_global();\nif app.is_none() {\n    // no Application::new() yet, or run() has returned\n}","typeGuard":"fn app_is_active() -> bool {\n    druid_shell::Application::try_global().is_some()\n}","tryCatchPattern":"// global() panics; prefer try_global:\nmatch druid_shell::Application::try_global() {\n    Some(app) => app,\n    None => { eprintln!(\"Application::new() must be called first\"); std::process::exit(1); }\n}","preventionTips":["Call Application::new() once at the top of main before any window/clipboard code.","Pass Application (or use try_global) instead of global() in library/test code.","Never call global() from static initializers or threads spawned before run().","In tests, provide an app fixture or abstraction over Application."],"tags":["rust","application-lifecycle","panic","druid-shell","gui"],"backgroundTag":"invalid-state-transition","analyzedSha":"0f8b1195e4e073f9597f2865299c3d18f8e4005f","analyzedAt":"2026-09-10T14:27:34.582Z","contentChangedAt":"2026-09-10T14:27:34.582Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}