{"record":{"id":"fb3f43550822acfa","repo":"linera-io/linera-protocol","slug":"expected-an-executionerror-got-self","errorCode":null,"errorMessage":"Expected an `ExecutionError`. Got: {self:#?}","messagePattern":"Expected an `ExecutionError`\\. Got: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"linera-core/src/worker.rs","lineNumber":534,"sourceCode":"                    execution_error,\n                    context,\n                ))),\n            },\n            error => Self::ChainError(Box::new(error)),\n        }\n    }\n}\n\n#[cfg(with_testing)]\nimpl WorkerError {\n    /// Returns the inner [`ExecutionError`] in this error.\n    ///\n    /// # Panics\n    ///\n    /// If this is not caused by an [`ExecutionError`].\n    pub fn expect_execution_error(self, expected_context: ChainExecutionContext) -> ExecutionError {\n        let WorkerError::ChainError(chain_error) = self else {\n            panic!(\"Expected an `ExecutionError`. Got: {self:#?}\");\n        };\n\n        let ChainError::ExecutionError(execution_error, context) = *chain_error else {\n            panic!(\"Expected an `ExecutionError`. Got: {chain_error:#?}\");\n        };\n\n        assert_eq!(context, expected_context);\n\n        *execution_error\n    }\n}\n\ntype ChainWorkerArc<S> = Arc<tokio::sync::RwLock<ChainWorkerState<S>>>;\ntype ChainWorkerWeak<S> = std::sync::Weak<tokio::sync::RwLock<ChainWorkerState<S>>>;\ntype ChainWorkerFuture<S> = Shared<oneshot::Receiver<ChainWorkerWeak<S>>>;\n\n/// Each map entry is a `Shared<oneshot::Receiver<Weak<...>>>`:\n///","sourceCodeStart":516,"sourceCodeEnd":552,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-core/src/worker.rs#L516-L552","documentation":"expect_execution_error (only built with with_testing) unwraps a WorkerError into its inner ExecutionError, asserting the error is a WorkerError::ChainError first. This panic means the worker returned a different top-level variant. Note a subtlety: ExecutionError::BlobsNotFound and EventsNotFound are hoisted to top-level WorkerError variants by the From impl, so an execution error of those kinds ALSO lands here.","triggerScenarios":"In tests: the code under test was expected to fail with an execution error but instead produced WorkerError::BlobsNotFound / WorkerError::EventsNotFound (missing blobs/events surfaced at upload), an arity/protocol error, or succeeded and returned a different wrapper.","commonSituations":"Test fixtures forgetting to publish required blobs before running the block, so the worker reports BlobsNotFound instead of the anticipated user-code error; test flakiness where an earlier setup step failed; refactors changing which layer emits the error.","solutions":["Look at the {self:#?} dump in the panic — it shows the actual variant; handle that variant (e.g. match WorkerError::BlobsNotFound) or fix setup so the expected execution error occurs.","If blobs/events are genuinely part of the scenario, publish them in the fixture first.","Check the From<ChainError> hoisting of BlobsNotFound/EventsNotFound when reasoning about which variant you will actually receive."],"exampleFix":"// before\nlet err = worker.handle_certificate(...).unwrap_err();\nlet exec = err.expect_execution_error(ctx); // panics: got BlobsNotFound\n\n// after\nmatch worker.handle_certificate(...).unwrap_err() {\n    WorkerError::BlobsNotFound(ids) => { /* publish blobs in fixture */ }\n    other => { let _ = other.expect_execution_error(ctx); }\n}","handlingStrategy":"type-guard","validationCode":"// Rust — assert the shape before unwrapping\nif !matches!(err, WorkerError::ChainError(_)) {\n    // handle BlobsNotFound / EventsNotFound / other variants explicitly\n}","typeGuard":"fn is_execution_error(err: &WorkerError) -> bool {\n    matches!(err, WorkerError::ChainError(inner) if matches!(**inner, ChainError::ExecutionError(_, _)))\n    // note: BlobsNotFound/EventsNotFound are hoisted to top-level WorkerError variants\n}","tryCatchPattern":"match err {\n    WorkerError::BlobsNotFound(ids) => { /* publish blobs in the fixture */ }\n    WorkerError::EventsNotFound(ids) => { /* publish events in the fixture */ }\n    other => { let _exec = other.expect_execution_error(ctx); }\n}","preventionTips":["Publish all required blobs/events in test fixtures before triggering the failing operation.","Remember the From<ChainError> hoisting of BlobsNotFound/EventsNotFound when predicting the variant you get.","Prefer explicit matches over expect_* helpers when the failing layer is uncertain."],"tags":["rust","testing","worker-error","debug-unwrap"],"backgroundTag":"unexpected-error-variant","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}