{"record":{"id":"4cfd4bf3944906c1","repo":"tracel-ai/burn","slug":"error-while-reading-data-use-try-execute-to-han","errorCode":null,"errorMessage":"Error while reading data: use `try_execute` to handle error at runtime","messagePattern":"Error while reading data: use `try_execute` to handle error at runtime","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-tensor/src/tensor/api/transaction.rs","lineNumber":68,"sourceCode":"    /// Crate-internal owning extraction of the underlying transaction primitive.\n    pub(crate) fn into_op(self) -> TransactionPrimitive<Dispatch> {\n        self.opaque.into_inner()\n    }\n\n    /// Add a [tensor](Tensor) to the transaction to be read.\n    pub fn register<const D: usize, K: crate::kind::Transaction>(\n        mut self,\n        tensor: Tensor<D, K>,\n    ) -> Self {\n        K::register_transaction(self.as_op_mut(), tensor.primitive);\n        self\n    }\n\n    /// Executes the transaction synchronously and returns the [data](TensorData) in the same order\n    /// in which they were [registered](Self::register).\n    pub fn execute(self) -> Vec<TensorData> {\n        burn_std::future::block_on(self.execute_async())\n            .expect(\"Error while reading data: use `try_execute` to handle error at runtime\")\n    }\n\n    /// Executes the transaction synchronously and returns the [data](TensorData) in the same\n    /// order in which they were [registered](Self::register).\n    ///\n    /// # Returns\n    ///\n    /// Any error that might have occurred since the last time the device was synchronized.\n    pub fn try_execute(self) -> Result<Vec<TensorData>, ExecutionError> {\n        burn_std::future::block_on(self.execute_async())\n    }\n\n    /// Executes the transaction asynchronously and returns the [data](TensorData) in the same order\n    /// in which they were [registered](Self::register).\n    pub async fn execute_async(self) -> Result<Vec<TensorData>, ExecutionError> {\n        self.into_op().execute_async().await\n    }\n}","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-tensor/src/tensor/api/transaction.rs#L50-L86","documentation":"Transaction::execute() blocks on execute_async() and unwraps with this message; if any registered tensor read failed (backend read error, device error, cancelled read), block_on returns None and the process panics. try_execute() is the Result-returning variant the library recommends for runtime error handling.","triggerScenarios":"Calling `transaction.execute()` when one of the registered tensors cannot be read back (device error, async read failure on WGPU, cancelled operation); executing a transaction in an async context where block_on cannot resolve.","commonSituations":"Multi-tensor result collection on GPU backends after a kernel failure; reading results inside tokio runtimes (block_on panics/deadlocks); batch metric extraction at end of training steps on WebGPU.","solutions":["Switch to `transaction.try_execute()` and handle the Err case","Ensure execute() is not called inside an async runtime; use execute_async().await instead","Check device health / backend logs for the underlying read failure","Retry the read after re-registering the tensors if the failure was transient"],"exampleFix":"// before\nlet data = txn.execute();\n// after\nmatch txn.try_execute() {\n    Ok(data) => data,\n    Err(e) => { log::error!(\"txn read failed: {e:?}\"); Vec::new() }\n}","handlingStrategy":"try-catch","validationCode":"// check async context before blocking\nassert!(!tokio::runtime::Handle::try_current().is_ok(), \"use execute_async in async context\");","typeGuard":null,"tryCatchPattern":"match txn.try_execute() {\n    Ok(data) => handle(data),\n    Err(e) => log::error!(\"transaction read failed: {e:?}\"),\n}","preventionTips":["Prefer try_execute() in production code","Use execute_async() inside async runtimes instead of blocking execute()","Monitor device health before large multi-tensor reads"],"tags":["async","sync-read","transaction","burn-tensor"],"backgroundTag":"blocking-async-read","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}