{"record":{"id":"4894c36f18271079","repo":"leptos-rs/leptos","slug":"at-caller-tried-to-spawn-a-future-with-executor","errorCode":null,"errorMessage":"At {caller}, tried to spawn a Future with Executor::spawn() before a global executor was initialized.","messagePattern":"At (.+?), tried to spawn a Future with Executor::spawn\\(\\) before a global executor was initialized\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"any_spawner/src/lib.rs","lineNumber":474,"sourceCode":"/// Handles the case where `Executor::spawn` is called without an initialized executor.\n#[cold] // Less likely path\n#[inline(never)]\n#[track_caller]\nfn handle_uninitialized_spawn(_fut: PinnedFuture<()>) {\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 called before a global executor was initialized. Task dropped.\"\n        );\n        // Drop the future implicitly after logging\n        drop(_fut);\n    }\n    #[cfg(all(debug_assertions, not(feature = \"tracing\")))]\n    {\n        panic!(\n            \"At {caller}, tried to spawn a Future with Executor::spawn() \\\n             before a global executor was initialized.\"\n        );\n    }\n    // In release builds (without tracing), call the specific no-op function.\n    #[cfg(not(debug_assertions))]\n    {\n        no_op_spawn(_fut);\n    }\n}\n\n/// 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\"))]","sourceCodeStart":456,"sourceCodeEnd":492,"githubUrl":"https://github.com/leptos-rs/leptos/blob/32d20f6c9d517451d77beb68d88c7716823dac41/any_spawner/src/lib.rs#L456-L492","documentation":"In debug builds without the tracing feature, handle_uninitialized_spawn panics with this message when Executor::spawn is called before any global executor was initialized. The {caller} interpolation tells you which call site attempted the spawn. It is the diagnostic (as opposed to release no-op) path for the uninitialized-spawn condition.","triggerScenarios":"Any Executor::spawn call while no global executor is set (set_executor never called), compiled with debug_assertions and without the tracing feature.","commonSituations":"Unit tests that spawn tasks but never init an executor; early code running before app bootstrap; feature-flag changes that disabled the executor setup path.","solutions":["Call any_spawner::spawn::set_executor(...) at the very start of the program/test before any spawn.","In tests, add a shared initializer (e.g. once_cell Lazy) that sets a tokio or wasm executor.","Check feature flags: enable tracing or the debug handler path you expect, or fix the init that a cfg gate disabled.","Read the {caller} value in the panic message to find the offending spawn call and defer it until after executor init."],"exampleFix":"// before\n#[test]\nfn spawns() {\n    Executor::spawn(async {}); // panics: no executor\n}\n// after\n#[test]\nfn spawns() {\n    any_spawner::spawn::set_executor(any_spawner::Executor::Tokio);\n    Executor::spawn(async {});\n}","handlingStrategy":"try-catch","validationCode":"// The panic cannot be caught in-process via catch_unwind for normal use; validate init instead:\nfn spawn_task<F: Future<Output = ()> + 'static>(fut: F) {\n    crate::init::ensure_global_executor(); // must run before any spawn\n    any_spawner::spawn(fut);\n}","typeGuard":null,"tryCatchPattern":"// only useful in tests/process boundaries\nstd::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {\n    any_spawner::spawn(async {});\n})).err().map(|p| eprintln!(\"spawn before executor init: {:?}\", p));","preventionTips":["Install the global executor at program/test start.","Search the codebase for Executor::spawn call sites and verify each runs after init.","Run debug builds in CI to catch this early with the caller info."],"tags":["async","executor","debug","panic","initialization"],"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"}