{"record":{"id":"f182d32acbe404e6","repo":"can1357/oh-my-pi","slug":"context-source","errorCode":null,"errorMessage":"{context}: {source}","messagePattern":"\\{context\\}: \\{source\\}","errorType":"error_code","errorClass":"WcError","httpStatus":null,"severity":"error","filePath":"crates/pi-builtins/src/wc.rs","lineNumber":793,"sourceCode":"\t\tmatch self {\n\t\t\tSelf::Auto => num_inputs > 1,\n\t\t\tSelf::Always | Self::Only => true,\n\t\t\tSelf::Never => false,\n\t\t}\n\t}\n}\n\n#[derive(Debug, Error)]\nenum WcError {\n\t#[error(\"extra operand {}\\nfile operands cannot be combined with --files0-from\", extra.quote())]\n\tFilesDisabled { extra: Cow<'static, OsStr> },\n\t#[error(\"when reading file names from standard input, no file name of '-' allowed\")]\n\tStdinReprNotAllowed,\n\t#[error(\"invalid zero-length file name\")]\n\tZeroLengthFileName,\n\t#[error(\"{path}:{idx}: invalid zero-length file name\")]\n\tZeroLengthFileNameCtx { path: Cow<'static, str>, idx: usize },\n\t#[error(\"{context}: {source}\")]\n\tIo {\n\t\tcontext: String,\n\t\t#[source]\n\t\tsource:  io::Error,\n\t},\n}\n\nimpl WcError {\n\tfn zero_len(ctx: Option<(&Input, usize)>) -> Self {\n\t\tmatch ctx {\n\t\t\tSome((input, idx)) => {\n\t\t\t\tlet path = match input {\n\t\t\t\t\tInput::Stdin(_) => STDIN_REPR.into(),\n\t\t\t\t\tInput::Path(path) => escape_name_wrapper(path.as_os_str()).into(),\n\t\t\t\t};\n\t\t\t\tSelf::ZeroLengthFileNameCtx { path, idx }\n\t\t\t},\n\t\t\tNone => Self::ZeroLengthFileName,","sourceCodeStart":775,"sourceCodeEnd":811,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/crates/pi-builtins/src/wc.rs#L775-L811","documentation":"WcError::Io { context, source } is wc's contextual IO error: it prefixes an io::Error with what wc was doing (`{context}: {source}`) and keeps the original as #[source]. The context tells you which phase failed (opening, reading, or stat-ing a file) while the source carries the errno-level cause.","triggerScenarios":"Any io::Error during wc's per-file processing — open() failing with EACCES/ENOENT, read() failing mid-stream, or metadata() failing — wrapped with the file-specific context string.","commonSituations":"wc on a nonexistent or misspelled path (ENOENT); unreadable files under another user (EACCES); reading special files with unusual semantics; disk/device errors on large inputs.","solutions":["Read `context` to see which file/operation failed, then the `source` errno for the cause","Check existence and permissions of the reported path (ls -l, or run as a user with access)","Skip unreadable inputs and continue with the remaining files in the list","For ENOENT, correct the path or regenerate the file list from a current find/ls"],"exampleFix":"// context: \"a.log: read\" source: Permission denied (os error 13)\n// after\nfor f in files {\n    if let Err(e) = std::fs::File::open(f) {\n        if e.kind() == std::io::ErrorKind::PermissionDenied {\n            eprintln!(\"skipping unreadable: {f}\");\n            continue;\n        }\n        return Err(e.into());\n    }\n    // process f\n}","handlingStrategy":"try-catch","validationCode":"fn wc_inputs_ok(paths: &[std::path::PathBuf]) -> Vec<(std::path::PathBuf, std::io::Error)> {\n    paths.iter()\n        .filter_map(|p| std::fs::File::open(p).err().map(|e| (p.clone(), e)))\n        .collect()\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(WcError::Io { context, source }) => {\n        eprintln!(\"{context}: {source}\");\n        if source.kind() == std::io::ErrorKind::NotFound {\n            // regenerate or drop the missing input\n        } else if source.kind() == std::io::ErrorKind::PermissionDenied {\n            // skip and continue with remaining files\n        }\n    }\n    other => other.map(|_| ()),\n}","preventionTips":["Pre-open (or stat) every input path before batch processing to fail fast on bad ones","Inspect source.kind()/raw_os_error() rather than parsing the Display string","Skip-and-log unreadable files instead of aborting the whole list","Regenerate file lists right before use to avoid stale (deleted) entries"],"tags":["io","wc","error-context","filesystem"],"backgroundTag":"io-read-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}