{"record":{"id":"ba795129cf1e93e9","repo":"can1357/oh-my-pi","slug":"multiple-output-files-specified","errorCode":null,"errorMessage":"multiple output files specified","messagePattern":"multiple output files specified","errorType":"exception","errorClass":"SortError","httpStatus":null,"severity":"error","filePath":"crates/pi-builtins/src/sort.rs","lineNumber":2621,"sourceCode":"\tReadFailed { path: PathBuf, error: std::io::Error },\n\n\t#[error(\"failed to open temporary file: {}\", strip_errno(.error))]\n\tOpenTmpFileFailed { error: std::io::Error },\n\n\t#[error(\"could not run compress program '{}': {}\", .prog, strip_errno(.error))]\n\tCompressProgExecutionFailed { prog: String, error: std::io::Error },\n\n\t#[error(\"{} terminated abnormally\", .prog.quote())]\n\tCompressProgTerminatedAbnormally { prog: String },\n\n\t#[error(\"cannot create temporary file in {}:\", .path.quote())]\n\tTmpFileCreationFailed { path: PathBuf },\n\n\t#[error(\"extra operand {}\\nfile operands cannot be combined with --files0-from\\nTry 'sort --help' for more information.\", .file.quote())]\n\tFileOperandsCombined { file: PathBuf },\n\n\n\t#[error(\"multiple output files specified\")]\n\tMultipleOutputFiles,\n\n\t#[error(\"when reading file names from standard input, no file name of '-' allowed\")]\n\tMinusInStdIn,\n\n\t#[error(\"no input from {}\", .file.quote())]\n\tEmptyInputFile { file: PathBuf },\n\n\t#[error(\"{}:{}: invalid zero-length file name\", .file.maybe_quote(), .line_num)]\n\tZeroLengthFileName { file: PathBuf, line_num: usize },\n}\n\nimpl SortError {\n\tfn message(message: impl Into<String>) -> Self {\n\t\tSelf::Message(message.into())\n\t}\n\n\tfn code(&self) -> i32 {","sourceCodeStart":2603,"sourceCodeEnd":2639,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/crates/pi-builtins/src/sort.rs#L2603-L2639","documentation":"SortError::MultipleOutputFiles is thrown when more than one output file is specified. sort accepts at most a single -o/--output target; extra operands after the first -o are rejected because output cannot be split across files.","triggerScenarios":"Invoking the sort builtin with multiple -o options (e.g. `sort -o a.txt -o b.txt input`) or otherwise arranging for more than one output file operand.","commonSituations":"Shell scripts that append `-o $OUT` in a loop, producing several output flags; copy-paste mistakes; config-driven wrappers that join an array of output paths into repeated -o flags.","solutions":["Pass exactly one -o/--output file.","Use `tee` or explicit separate invocations if multiple outputs are genuinely needed.","Fix wrapper scripts to take the last/single configured output path rather than joining an array."],"exampleFix":"// before\nsort -o a.txt -o b.txt input.txt\n// after\nsort -o a.txt input.txt","handlingStrategy":"validation","validationCode":"// ensure at most one -o/--output before invoking sort\nconst outputs = args.filter(a => a === \"-o\" || a === \"--output\");\nif (outputs.length > 1) throw new Error(\"at most one -o/--output is allowed\");","typeGuard":null,"tryCatchPattern":"try {\n  await sort(args);\n} catch (err) {\n  if (String(err).includes(\"multiple output files\")) {\n    // fall back to the last configured output only\n    await sort(dedupeOutputFlags(args));\n  } else throw err;\n}","preventionTips":["Never append -o inside loops that build sort arguments.","Deduplicate output flags in wrapper scripts, keeping the last value.","Use tee for genuine multi-destination output instead of multiple -o flags.","Assert single-output configuration at script startup."],"tags":["cli","sort","usage-error","argument-validation"],"backgroundTag":"too-many-arguments","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}