{"record":{"id":"c7456ea3dbf7c184","repo":"helix-editor/helix","slug":"failed-to-send-save-event","errorCode":null,"errorMessage":"failed to send save event: {}","messagePattern":"failed to send save event: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"helix-view/src/editor.rs","lineNumber":2266,"sourceCode":"\n        // When a file is written to, notify the file event handler.\n        // Note: This can be removed once proper file watching is implemented.\n        let handler = self.language_servers.file_event_handler.clone();\n        let future = async move {\n            let res = doc_save_future.await;\n            if let Ok(event) = &res {\n                handler.file_changed(event.path.clone());\n            }\n            res\n        };\n\n        use futures_util::stream;\n\n        self.saves\n            .get(&doc_id)\n            .ok_or_else(|| anyhow::format_err!(\"saves are closed for this document!\"))?\n            .send(stream::once(Box::pin(future)))\n            .map_err(|err| anyhow!(\"failed to send save event: {}\", err))?;\n\n        self.write_count += 1;\n\n        Ok(())\n    }\n\n    pub fn resize(&mut self, area: Rect) {\n        if self.tree.resize(area) {\n            self._refresh();\n        };\n    }\n\n    pub fn focus(&mut self, view_id: ViewId) {\n        if self.tree.focus == view_id {\n            return;\n        }\n\n        // Reset mode to normal and ensure any pending changes are committed in the old document.","sourceCodeStart":2248,"sourceCodeEnd":2284,"githubUrl":"https://github.com/helix-editor/helix/blob/079a789e8cb08ead67f19e1971a1b7438b37354b/helix-view/src/editor.rs#L2248-L2284","documentation":"Editor::save funnels each document's saves through a per-document stream (self.saves). The error fires when .send(stream::once(future)) on that stream returns Err, meaning the receiving end of the save pipeline for that document is already closed. In practice the channel is closed during editor/document teardown, so a save requested in that window fails with \"failed to send save event\".","triggerScenarios":"Issuing a save (including format-on-save or write-then-close sequences) for a document whose save handler has been dropped: saving during editor shutdown, a race between closing a view/document and a pending save, or an embedder calling save after the editor event loop stopped draining saves.","commonSituations":"Automation or plugins that trigger writes while the editor is exiting; rapid :q with pending autosave/format-on-save; embedders (helix as a library) that shut down the event loop with saves still queued.","solutions":["Ensure saves are not requested after the document or editor begins closing (check the document is still open / editor not shutting down before calling save).","If it happens on exit with format-on-save or autosave enabled, disable those for the session or update Helix — teardown races here are worth an upstream issue if reproducible.","For embedders, keep the event loop running until all write_count saves settle before dropping the editor."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if !editor.saves_for_doc_open(doc_id) { // expose/check that the per-doc save stream exists\n    return Err(anyhow!(\"save pipeline already closed for {doc_id:?}\"));\n}\neditor.save(doc_id, /* ... */)?;","typeGuard":null,"tryCatchPattern":"if let Err(err) = editor.save(/* ... */) {\n    if err.to_string().contains(\"failed to send save event\") {\n        // channel closed during teardown: not retryable, surface but do not crash\n        log::debug!(\"save dropped during shutdown: {err:#}\");\n    } else {\n        return Err(err);\n    }\n}","preventionTips":["Do not issue saves after a document/editor close begins; sequence shutdown before write triggers.","In embedders, drain the save pipeline before dropping the Editor.","Treat this specific send failure as a teardown race, not a disk failure — don't misreport it to users as I/O."],"tags":["save","channel","shutdown","helix","rust"],"backgroundTag":null,"analyzedSha":"079a789e8cb08ead67f19e1971a1b7438b37354b","analyzedAt":"2026-08-16T09:09:59.668Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}