{"record":{"id":"4a7ada64ad183835","repo":"leptos-rs/leptos","slug":"at-caller-tried-to-spawn-a-future-with-executor-4a7ada","errorCode":null,"errorMessage":"At {caller}, tried to spawn a Future with Executor::spawn_local() before a global executor was initialized.","messagePattern":"At (.+?), tried to spawn a Future with Executor::spawn_local\\(\\) before a global executor was initialized\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"any_spawner/src/lib.rs","lineNumber":504,"sourceCode":"/// Handles the case where `Executor::spawn_local` is called without an initialized executor.\n#[cold] // Less likely path\n#[inline(never)]\n#[track_caller]\nfn handle_uninitialized_spawn_local(_fut: PinnedLocalFuture<()>) {\n    let caller = std::panic::Location::caller();\n    #[cfg(all(debug_assertions, feature = \"tracing\"))]\n    {\n        tracing::error!(\n            target: \"any_spawner\",\n            spawn_caller=%caller,\n            \"Executor::spawn_local called before a global executor was initialized. \\\n            Task likely dropped or panicked.\"\n        );\n        // Fall through to panic or no-op depending on build/target\n    }\n    #[cfg(all(debug_assertions, not(feature = \"tracing\")))]\n    {\n        panic!(\n            \"At {caller}, tried to spawn a Future with \\\n             Executor::spawn_local() before a global executor was initialized.\"\n        );\n    }\n    // In release builds (without tracing), call the specific no-op function (which usually panics).\n    #[cfg(not(debug_assertions))]\n    {\n        no_op_spawn_local(_fut);\n    }\n}\n","sourceCodeStart":486,"sourceCodeEnd":515,"githubUrl":"https://github.com/leptos-rs/leptos/blob/32d20f6c9d517451d77beb68d88c7716823dac41/any_spawner/src/lib.rs#L486-L515","documentation":"Debug-build panic raised by handle_uninitialized_spawn_local when Executor::spawn_local is called before a global spawn_local executor is registered. It includes the {caller} location to identify the offending call site. It is the debug counterpart of the release-mode no_op_spawn_local panic.","triggerScenarios":"Executor::spawn_local invoked with no configured global spawn_local function, in a debug build without the tracing feature.","commonSituations":"Tests or early startup code using spawn_local before executor setup; wasm code paths where only the non-local executor was registered; switching frameworks/feature flags and losing the LocalSet registration.","solutions":["Register the local executor via any_spawner::spawn_local::set_executor(...) before the first spawn_local call.","Ensure the registration happens on the same thread the futures are spawned on (LocalSet semantics).","Use the {caller} in the message to locate the premature spawn_local and move it after initialization.","If the message is replaced by a no-op panic in release, reproduce in debug to get the caller info, then fix init order."],"exampleFix":"// before\nfn handler() {\n    Executor::spawn_local(async { update_dom().await }); // panics in debug\n}\n// after\nfn handler() {\n    ensure_executor_installed(); // any_spawner::spawn_local::set_executor(...)\n    Executor::spawn_local(async { update_dom().await });\n}","handlingStrategy":"try-catch","validationCode":"fn spawn_local_task<F: Future<Output = ()> + 'static>(fut: F) {\n    crate::init::ensure_local_executor_installed();\n    any_spawner::spawn_local(fut);\n}","typeGuard":null,"tryCatchPattern":"std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {\n    any_spawner::spawn_local(async {});\n})).err().map(|p| eprintln!(\"spawn_local before executor init: {:?}\", p));","preventionTips":["Use the {caller} in debug panics to locate premature spawn_local calls.","Keep executor installation on the same thread as spawn_local (LocalSet).","Add an integration test that exercises spawn_local paths in debug mode."],"tags":["async","executor","spawn-local","debug","panic"],"backgroundTag":"no-global-executor-configured","analyzedSha":"32d20f6c9d517451d77beb68d88c7716823dac41","analyzedAt":"2026-09-01T18:55:42.580Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}