{"record":{"id":"991c5eefdd662401","repo":"Y2Z/monolith","slug":"could-not-prepare-output","errorCode":null,"errorMessage":"could not prepare output","messagePattern":"could not prepare output","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/main.rs","lineNumber":283,"sourceCode":"    // Initiate session\n    let output_format = options.output_format.clone();\n    let silent = options.silent;\n    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()),","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/Y2Z/monolith/blob/a6fc8d009514b2ea271dda2539f19a1f479ebfab/src/main.rs#L265-L301","documentation":"This panic comes from the `expect(\"could not prepare output\")` on `Output::new()` in main.rs:283 (the STDIN-pipe branch, target == \"-\"). `Output::new` returns `Err(io::Error)` only when a destination file path was given and `fs::File::create(final_destination)` fails — i.e. the output cannot be opened for writing. It is a hard panic, not a graceful error, because it happens inside the Ok-branch of document creation after all network work succeeded.","triggerScenarios":"Running monolith with `-` (or with piped input via `target == \"-\"`) AND a non-empty `-o/--output` destination whose file cannot be created: nonexistent parent directory, permission denied, path is a directory, invalid characters in the path (possibly produced by `format_output_path` substituting the page title into the filename), disk full, or read-only filesystem.","commonSituations":"Users pipe a page in via stdin (`curl ... | monolith - -o out.html`) while the output directory doesn't exist or is read-only; titles containing `/` or other filesystem-illegal characters interpolated into the output path; running as a user without write permission in the current directory; on Windows, reserved characters (`:`, `?`, `*`) coming from a document title.","solutions":["Create the parent directory of the output path first (mkdir -p) or correct the -o path typo.","Verify write permissions for the user running monolith on the destination directory.","Quote/escape the -o argument and avoid letting the document title inject illegal characters into the filename; pass an explicit simple filename.","Check available disk space and that the destination is not itself a directory.","If scripting, guard with a pre-flight writability check (e.g. `touch <dir>/.write_test`) before invoking monolith."],"exampleFix":"// before (shell)\ncat page.html | monolith - -o out/page.html   # out/ does not exist -> panic\n\n// after (shell)\nmkdir -p out && cat page.html | monolith - -o out/page.html","handlingStrategy":"validation","validationCode":"#!/usr/bin/env bash\nout=\"out/page.html\"\ndir=\"$(dirname \"$out\")\"\nmkdir -p \"$dir\" || exit 1\n[ -d \"$out\" ] && { echo \"output path is a directory\"; exit 1; }\n[ -w \"$dir\" ] || { echo \"no write permission in $dir\"; exit 1; }\nprintf '' > \"$out.tmp\" && rm \"$out.tmp\" || { echo \"cannot create $out\"; exit 1; }\ncat page.html | monolith - -o \"$out\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always create the destination directory (mkdir -p) before running with -o.","Pass an explicit, simple filename; avoid templates that interpolate the page title into the path.","Check directory writability in CI/scripts before invoking monolith.","Remember this is a panic (exit code 101), not a graceful error — treat non-zero exits accordingly."],"tags":["io","filesystem","panic","output-file"],"backgroundTag":"file-write-permission-denied","analyzedSha":"a6fc8d009514b2ea271dda2539f19a1f479ebfab","analyzedAt":"2026-09-05T20:13:04.517Z","contentChangedAt":"2026-09-05T20:13:04.517Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}