{"record":{"id":"2616965456b8514e","repo":"uutils/coreutils","slug":"csplit-write-split-not-created","errorCode":null,"errorMessage":"csplit-write-split-not-created","messagePattern":"csplit-write-split-not-created","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/uu/csplit/src/csplit.rs","lineNumber":303,"sourceCode":"    /// The current split will not keep any of the read input lines.\n    fn as_dev_null(&mut self) {\n        self.dev_null = true;\n    }\n\n    /// Writes the line to the current split.\n    /// If `self.dev_null` is true, then the line is discarded.\n    ///\n    /// # Errors\n    ///\n    /// Some [`io::Error`] may occur when attempting to write the line.\n    fn writeln(&mut self, line: &str) -> io::Result<()> {\n        if !self.dev_null {\n            if let Some(ref mut current_writer) = self.current_writer {\n                let bytes = line.as_bytes();\n                current_writer.write_all(bytes)?;\n                self.size += bytes.len();\n            } else {\n                panic!(\"{}\", translate!(\"csplit-write-split-not-created\"))\n            }\n        }\n        Ok(())\n    }\n\n    /// Perform some operations after completing a split, i.e., either remove it\n    /// if the [`options::ELIDE_EMPTY_FILES`] option is enabled, or print how much bytes were written\n    /// to it if [`options::QUIET`] is disabled.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if flushing the writer fails.\n    fn finish_split(&mut self) -> Result<(), CsplitError> {\n        if !self.dev_null {\n            // Flush the writer to ensure all data is written and errors are detected\n            if let Some(ref mut writer) = self.current_writer {\n                let file_name = self.options.split_name.get(self.counter - 1);\n                writer","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/uutils/coreutils/blob/9ff4114e82c8fb80420fd4fb6a319bd3227095e0/src/uu/csplit/src/csplit.rs#L285-L321","documentation":"This panic occurs in csplit's output writer when a line is about to be written but no current split file writer has been created yet. csplit creates the writer lazily when a split file is opened; writing before any split is open means internal state is inconsistent (the writer was closed or never initialized). It is an unrecoverable panic rather than an io::Error because it indicates a bug in csplit's split-state machine, not user input.","triggerScenarios":"Internal: writeln() is invoked while self.current_writer is None and dev_null is false — i.e., do_to_line/do_to_match tries to emit output before a split file was opened or after it was finished/removed.","commonSituations":"Practically only hit with a buggy or patched csplit build, custom pattern scripts whose first operation is a write with no preceding split creation, or corrupted state when the output stream was removed mid-run.","solutions":["Update Rust coreutils to the latest version; if reproducible, file a bug with the exact csplit pattern arguments","Check your csplit pattern/script: ensure the first operation opens a split before output is written","Verify the output files were not removed/closed externally mid-run (e.g., another process deleting split files)","As a workaround, redirect output to a directory you control and avoid patterns that address offsets before the first split"],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"// panic, not Result — run csplit and check exit status\nmatch Command::new(\"csplit\").args([...]).status() {\n    Ok(s) if s.success() => { /* ok */ }\n    Ok(s) => eprintln!(\"csplit failed: {}\", s),\n    Err(e) => eprintln!(\"spawn error: {e}\"),\n}","preventionTips":["Keep csplit patterns simple and ensure output is written only after a split is opened","Use a maintained build of the coreutils implementation","Avoid running concurrent csplit instances writing to the same output files"],"tags":["csplit","panic","internal-state"],"backgroundTag":"writer-not-initialized","analyzedSha":"9ff4114e82c8fb80420fd4fb6a319bd3227095e0","analyzedAt":"2026-08-31T11:11:36.175Z","contentChangedAt":"2026-08-31T11:11:36.175Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}