{"record":{"id":"b82fc79589b0bcbb","repo":"zellij-org/zellij","slug":"failed-to-send-message-to-channel-b82fc7","errorCode":null,"errorMessage":"failed to send message to channel","messagePattern":"failed to send message to channel","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"zellij-utils/src/errors.rs","lineNumber":972,"sourceCode":"    ///\n    /// Takes the `SendError` and creates an `anyhow` error type with the message that was sent\n    /// (formatted as string), attaching the [`ErrorContext`] as anyhow context to it.\n    impl<T: std::fmt::Debug, U> ToAnyhow<U>\n        for Result<U, crate::channels::SendError<(T, ErrorContext)>>\n    {\n        fn to_anyhow(self) -> anyhow::Result<U> {\n            match self {\n                Ok(val) => anyhow::Ok(val),\n                Err(e) => {\n                    let (msg, context) = e.into_inner();\n                    if *crate::consts::DEBUG_MODE.get().unwrap_or(&true) {\n                        Err(anyhow::anyhow!(\n                            \"failed to send message to channel: {:#?}\",\n                            msg\n                        ))\n                        .with_context(|| context.to_string())\n                    } else {\n                        Err(anyhow::anyhow!(\"failed to send message to channel\"))\n                            .with_context(|| context.to_string())\n                    }\n                },\n            }\n        }\n    }\n\n    impl<U> ToAnyhow<U> for Result<U, std::sync::PoisonError<U>> {\n        fn to_anyhow(self) -> anyhow::Result<U> {\n            match self {\n                Ok(val) => anyhow::Ok(val),\n                Err(e) => {\n                    if *crate::consts::DEBUG_MODE.get().unwrap_or(&true) {\n                        Err(anyhow::anyhow!(\"cannot acquire poisoned lock for {e:#?}\"))\n                    } else {\n                        Err(anyhow::anyhow!(\"cannot acquire poisoned lock\"))\n                    }\n                },","sourceCodeStart":954,"sourceCodeEnd":990,"githubUrl":"https://github.com/zellij-org/zellij/blob/bf8d23a4f774abf27a108da2a1a2689e7d8d0d23/zellij-utils/src/errors.rs#L954-L990","documentation":"The non-DEBUG_MODE variant of the same ToAnyhow impl for channel SendError<(T, ErrorContext)> in zellij-utils/src/errors.rs: the send failed because the receiver side was dropped, and the message payload is withheld in production builds. The attached ErrorContext string identifies the sending subsystem.","triggerScenarios":"Identical mechanism to the debug variant: .send((msg, ErrorContext)).to_anyhow() on a channel whose consumer thread has exited (panic, teardown, or dropped receiver), with consts::DEBUG_MODE off so only the generic message is shown.","commonSituations":"Production/default builds where a session was killed while dependent threads still sent; a background thread panicked silently earlier; detach/exit races between client and server threads.","solutions":["Confirm the target session/thread still exists (zellij list-sessions, process list for the zellij server).","Re-run with DEBUG_MODE enabled to get variant [68] with the full undeliverable message — that shows exactly what was being sent when the channel died.","Search logs upward for the first panic/exit — that closed the channel; report it with backtrace.","Update zellij."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// production builds: same handling, generic message\nmatch sender.send((msg, ErrorContext::new())).to_anyhow() {\n    Ok(_) => {},\n    Err(e) if e.to_string().starts_with(\"failed to send message to channel\") => {\n        log::warn!(\"peer thread exited; shutting down this worker\");\n        return;\n    },\n    Err(e) => return Err(e),\n}","preventionTips":["Enable DEBUG_MODE during diagnosis to upgrade this to variant [68] with the full message dump.","Design worker threads so the receiver's exit also signals the sender (shared AtomicBool/JOB flag), avoiding sends to dead peers.","Log receiver-thread panics loudly so the closed-channel symptom is never the first evidence."],"tags":["zellij","rust","channel","send-error","shutdown-race"],"backgroundTag":"send-on-closed-channel","analyzedSha":"bf8d23a4f774abf27a108da2a1a2689e7d8d0d23","analyzedAt":"2026-08-19T07:42:58.758Z","contentChangedAt":"2026-08-19T07:42:58.758Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}