{"record":{"id":"74386054a1423203","repo":"Y2Z/monolith","slug":"could-not-write-output","errorCode":null,"errorMessage":"could not write output","messagePattern":"could not write output","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/main.rs","lineNumber":286,"sourceCode":"    let session: Session = Session::new(cache, cookies, options);\n\n    // Retrieve target from source and output result\n    if cli.target == \"-\" {\n        // Read input from pipe (STDIN)\n        let data: Vec<u8> = read_stdin();\n\n        match create_monolithic_document_from_data(session, data, None, None) {\n            Ok((result, title)) => {\n                // Define output\n                let mut output = Output::new(\n                    &destination.unwrap_or(String::new()),\n                    &title.unwrap_or_default(),\n                    output_format,\n                )\n                .expect(\"could not prepare output\");\n\n                // Write result into STDOUT or file\n                output.write(&result).expect(\"could not write output\");\n            }\n            Err(error) => {\n                if !silent {\n                    print_error_message(&format!(\"Error: {}\", error));\n                }\n\n                exit_code = 1;\n            }\n        }\n    } else {\n        match create_monolithic_document(session, cli.target) {\n            Ok((result, title)) => {\n                // Define output\n                let mut output = Output::new(\n                    &destination.unwrap_or(String::new()),\n                    &title.unwrap_or_default(),\n                    output_format,\n                )","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/Y2Z/monolith/blob/a6fc8d009514b2ea271dda2539f19a1f479ebfab/src/main.rs#L268-L304","documentation":"This panic comes from `output.write(&result).expect(\"could not write output\")` in main.rs:286 (the STDIN-pipe branch). `Output::write` propagates `io::Error` from `write_all`/`flush` on either stdout or the destination file. The output object was created successfully, but writing/flushing the rendered monolithic document bytes failed, so the program panics after all fetching work has already completed.","triggerScenarios":"The destination file became unwritable after creation (disk full mid-write, quota exceeded, permission revoked), or writing to stdout failed because the pipe was closed early (e.g. `monolith - | head -n 1` causing SIGPIPE/EPIPE) or stdout redirected to a full/unwritable target.","commonSituations":"Disk filled up while saving a very large page; output piped into `head`, `less -F`, or a process that exits early, closing the pipe; NFS/network mounts dropping mid-write; tmpfs quota exceeded; antivirus or backup software locking the file on Windows.","solutions":["Check free disk space and write quota on the destination volume.","Avoid piping output into commands that close early (`head`); use `monolith - > file.html` or capture to a file first.","Verify the destination file/mount is writable and not locked by another process.","Re-run without piping stdout; if the panic was EPIPE on stdout, redirect to a file.","For automation, wrap the call so a panic exit (code 101) is detected and retried or reported."],"exampleFix":"// before (shell)\nmonolith - -o page.html | head -c 100   # closes pipe -> \"could not write output\" panic\n\n// after (shell)\nmonolith - -o page.html   # write fully to file, no truncated pipe consumer","handlingStrategy":"try-catch","validationCode":"#!/usr/bin/env bash\ndf -h . | awk 'NR==2 {exit ($5+0 > 95 ? 1 : 0)}' || { echo \"disk nearly full\"; exit 1; }\nmonolith - -o page.html || code=$?\n[ \"$code\" = \"101\" ] && echo \"output write panicked (disk/pipe?)\"","typeGuard":null,"tryCatchPattern":"match std::panic::catch_unwind(|| {\n    output.write(&result)\n}) {\n    Ok(Ok(())) => {},\n    Ok(Err(e)) => eprintln!(\"write failed: {}\", e),\n    Err(_) => eprintln!(\"panicked while writing output (disk full or closed pipe?)\"),\n}","preventionTips":["Don't pipe monolith output into commands that exit early (head, less -F); redirect to a file instead.","Monitor free disk space when saving large pages.","Avoid writing output to network/removable mounts that can drop mid-write.","Detect panic exit code 101 in automation to distinguish write failures from fetch failures."],"tags":["io","filesystem","panic","stdout","broken-pipe"],"backgroundTag":"broken-pipe","analyzedSha":"a6fc8d009514b2ea271dda2539f19a1f479ebfab","analyzedAt":"2026-09-05T20:13:04.517Z","contentChangedAt":"2026-09-05T20:13:04.517Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}