{"record":{"id":"0cf11acc7ae1d121","repo":"dbt-labs/dbt-core","slug":"e","errorCode":null,"errorMessage":"{e}\n{:?}","messagePattern":"\\{e\\}\n\\{:\\?\\}","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbt-runtime/src/handle.rs","lineNumber":99,"sourceCode":"        Handle {\n            inner: Arc::new(inner),\n        }\n    }\n\n    /// Returns the handle set for the current thread.\n    ///\n    /// # Panics\n    ///\n    /// Panics if called outside a [`Handle::enter`] scope. In particular this\n    /// panics inside a blocking task, by design — see the module docs. For a\n    /// non-panicking version see [`Handle::try_current`].\n    #[track_caller]\n    pub fn current() -> Handle {\n        match Handle::try_current() {\n            Ok(handle) => handle,\n            Err(e) => {\n                if cfg!(debug_assertions) {\n                    panic!(\"{e}\\n{:?}\", std::backtrace::Backtrace::force_capture());\n                } else {\n                    panic!(\"{e}\");\n                }\n            }\n        }\n    }\n\n    /// Returns the handle set for the current thread, if any.\n    pub fn try_current() -> Result<Handle, TryCurrentError> {\n        current::with_current(Handle::clone)\n    }\n\n    /// Sets this handle as the current one until the returned guard is dropped.\n    pub fn enter(&self) -> EnterGuard<'_> {\n        EnterGuard {\n            _guard: current::try_set_current(self)\n                .expect(\"cannot enter a runtime handle while the thread is shutting down\"),\n            _handle_lifetime: PhantomData,","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-runtime/src/handle.rs#L81-L117","documentation":"Handle::current() returns the runtime handle for the calling thread, but only if the thread is inside a runtime context (a worker thread or inside Handle::enter). If try_current() fails — meaning no runtime is associated with the thread — this panics; in debug builds it also captures and prints a forced backtrace to aid diagnosis.","triggerScenarios":"Calling Handle::current() from a thread with no runtime context: plain std::thread::spawn outside the runtime, blocking code moved off-runtime without re-entering, calling it in main() before starting the runtime, or calling it inside block_in_place after the runtime was shut down.","commonSituations":"Using Handle::current() in a helper invoked from both async and sync code; spawning a std thread that then tries to spawn async tasks via a runtime handle; running tests with #[test] instead of #[tokio::test] while calling runtime-aware APIs.","solutions":["Use Handle::try_current() and handle the Err case instead of panicking.","Only call current() on threads inside the runtime, or enter the runtime first: `let _g = handle.enter();` on the foreign thread.","Pass the Handle explicitly into functions/threads instead of relying on thread-local context.","Annotate async tests with #[tokio::test] and run blocking work via spawn_blocking, not std threads, when runtime APIs are needed."],"exampleFix":"// before\nlet handle = Handle::current(); // panics off-runtime\n\n// after\nlet handle = match Handle::try_current() {\n    Ok(h) => h,\n    Err(_) => return fallback_handle_or_default(),\n};","handlingStrategy":"try-catch","validationCode":"// pre-check before calling current()\nif Handle::try_current().is_err() {\n    eprintln!(\"not inside a runtime context; skipping Handle::current()\");\n    return;\n}","typeGuard":"fn in_runtime() -> bool {\n    Handle::try_current().is_ok()\n}","tryCatchPattern":"let handle = match Handle::try_current() {\n    Ok(h) => h,\n    Err(e) => {\n        log::warn!(\"no runtime on this thread: {e}; using fallback\");\n        return fallback();\n    }\n};","preventionTips":["Prefer try_current() over current() in library/API-boundary code.","Spawn async work with tokio::spawn / spawn_blocking rather than std::thread when runtime context is needed.","Pass Handle explicitly to functions that may run on foreign threads.","Use #[tokio::test] so tests execute inside a runtime context."],"tags":["rust","runtime","panic","async","tokio"],"backgroundTag":"internal-invariant-violation","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}