{"record":{"id":"bd174b69f945e421","repo":"can1357/oh-my-pi","slug":"error-bd174b","errorCode":null,"errorMessage":"{}: {error}","messagePattern":"\\{\\}: \\{error\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pi-builtins/src/cut.rs","lineNumber":745,"sourceCode":"fn cut_files<'a, I>(host: &mut Host, filenames: I, mode: &Mode)\nwhere\n\tI: IntoIterator<Item = &'a OsString>,\n{\n\tlet inputs = filenames\n\t\t.into_iter()\n\t\t.map(|name| {\n\t\t\tlet path = if name == \"-\" { None } else { Some(host.resolve(name)) };\n\t\t\t(name, path)\n\t\t})\n\t\t.collect::<Vec<_>>();\n\tlet mut stdin_read = false;\n\tlet mut failed = false;\n\tlet mut out = host.stdout_writer();\n\n\tfor (filename, path) in inputs {\n\t\tlet result = if let Some(path) = path {\n\t\t\tFile::open(path)\n\t\t\t\t.map_err(|error| io::Error::new(error.kind(), format!(\"{}: {error}\", filename.maybe_quote())))\n\t\t\t\t.and_then(|file| match mode {\n\t\t\t\t\tMode::Bytes(ranges, opts) | Mode::Characters(ranges, opts) => {\n\t\t\t\t\t\tcut_bytes(file, &mut out, ranges, opts)\n\t\t\t\t\t},\n\t\t\t\t\tMode::Fields(ranges, opts) => cut_fields(file, &mut out, ranges, opts),\n\t\t\t\t})\n\t\t} else if stdin_read {\n\t\t\tcontinue;\n\t\t} else {\n\t\t\tstdin_read = true;\n\t\t\tmatch mode {\n\t\t\t\tMode::Bytes(ranges, opts) | Mode::Characters(ranges, opts) => {\n\t\t\t\t\tcut_bytes(&mut host.stdin, &mut out, ranges, opts)\n\t\t\t\t},\n\t\t\t\tMode::Fields(ranges, opts) => cut_fields(&mut host.stdin, &mut out, ranges, opts),\n\t\t\t}\n\t\t};\n\t\tif let Err(error) = result {","sourceCodeStart":727,"sourceCodeEnd":763,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/crates/pi-builtins/src/cut.rs#L727-L763","documentation":"When cut processes input files, any File::open failure is re-wrapped as io::Error with the message `<filename>: <underlying error>` (filename via maybe_quote). cut_files collects these per-file failures, marks the run failed, and cut_main reports the aggregate. The inner error is the real cause (ENOENT, EACCES, EISDIR, etc.).","triggerScenarios":"Calling `cut -d, -f1 missing.csv`, cutting a file without read permission, or passing a directory as an input file — any input path File::open rejects.","commonSituations":"Typos in filenames, files deleted between listing and processing in pipelines, scripts running as a user lacking permissions, or glob expansion passing directories to cut.","solutions":["Read the suffix after the colon for the real OS error and fix that (create the file, fix the path, or adjust permissions)","Check `ls -l` on the reported filename to confirm existence and read permission","Skip directories explicitly (`find . -type f | xargs cut ...`) instead of letting cut open them","Wrap cut_main invocation so per-file failures are logged while remaining files still process (cut already continues; check `failed` for exit status)"],"exampleFix":"// before\ncut -d: -f1 /etc/passwd.bak  // ENOENT\n// after\nif [ -r /etc/passwd.bak ]; then cut -d: -f1 /etc/passwd.bak; else echo \"missing\" >&2; fi","handlingStrategy":"validation","validationCode":"for f in files { let md = std::fs::metadata(f).map_err(|e| format!(\"{}: {}\", f, e))?; if md.is_dir() { return Err(format!(\"{}: is a directory\", f)); } }","typeGuard":null,"tryCatchPattern":"// cut already continues past failures; inspect the resultfor (filename, path) in inputs { if let Err(e) = open_and_cut(path) { eprintln!(\"cut: {}\", e); failed = true; } }if failed { std::process::exit(1); }","preventionTips":["Check file existence and readability with test -r before feeding files to cut","Exclude directories from generated file lists (find -type f)","Re-check files that may be deleted concurrently; treat per-file errors as expected in pipelines"],"tags":["io","filesystem","permissions","rust"],"backgroundTag":"file-open-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}