{"record":{"id":"aa1f5c6939815a09","repo":"can1357/oh-my-pi","slug":"failed-to-get-attributes-of","errorCode":null,"errorMessage":"failed to get attributes of {}: {}","messagePattern":"failed to get attributes of (.+?): (.+?)","errorType":"error_code","errorClass":"TouchError","httpStatus":null,"severity":"error","filePath":"crates/pi-builtins/src/touch.rs","lineNumber":45,"sourceCode":"use rustix::fs::Timestamps;\n#[cfg(unix)]\nuse rustix::fs::futimens;\n#[cfg(target_os = \"linux\")]\nuse uucore::libc;\nuse uucore::{display::Quotable, parser::shortcut_value_parser::ShortcutValueParser};\n\nuse brush_core::{ShellExtensions, builtins::Registration};\nuse thiserror::Error as ThisError;\n\nuse crate::host::{Host, Utility, format_usage, matches_parser, util};\n\n#[derive(Debug, ThisError)]\nenum TouchError {\n\t#[error(\"Unable to parse date: {0}\")]\n\tInvalidDateFormat(String),\n\t#[error(\"Source has invalid access or modification time: {0}\")]\n\tInvalidFiletime(FileTime),\n\t#[error(\"failed to get attributes of {}: {}\", .0.quote(), io_error(.1))]\n\tReferenceFileInaccessible(PathBuf, std::io::Error),\n\t#[cfg(windows)]\n\t#[error(\"GetFinalPathNameByHandleW failed with code {0}\")]\n\tWindowsStdoutPathError(String),\n\t#[error(\"{0}\")]\n\tMessage(String),\n}\n\nfn io_error(error: &std::io::Error) -> String {\n\tif error.raw_os_error().is_some() {\n\t\tmatch error.kind() {\n\t\t\tErrorKind::NotFound => \"No such file or directory\".into(),\n\t\t\tErrorKind::PermissionDenied => \"Permission denied\".into(),\n\t\t\tErrorKind::AlreadyExists => \"Already exists\".into(),\n\t\t\tErrorKind::WouldBlock => \"Would block\".into(),\n\t\t\t_ => error.to_string().split(\" (os error \").next().unwrap_or_default().into(),\n\t\t}\n\t} else {","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/crates/pi-builtins/src/touch.rs#L27-L63","documentation":"TouchError::ReferenceFileInaccessible is raised when `touch -r <reference>` cannot stat the reference file whose timestamps should be copied. The library needs the reference's atime/mtime via metadata() and wraps the io::Error with the quoted path. It mirrors GNU coreutils' 'failed to get attributes of' diagnostics.","triggerScenarios":"Calling touch with `-r/--reference=FILE` where FILE does not exist, lacks read permission on its directory, or the path is otherwise unstat-able (broken symlink target, permission denied).","commonSituations":"Copy-pasting a reference path with a typo; referencing a file in another user's directory; the reference file was deleted between listing and touching; running without sufficient privileges (e.g. in restricted CI containers).","solutions":["Verify the reference file exists and its parent directory grants you search (execute) permission","Re-run with the correct path or create the reference file first","If you only need fixed timestamps, use -d/-t with an explicit date instead of -r","Check quoting of the path (spaces/special characters) in your shell invocation"],"exampleFix":"// before: touch -r missing_ref.txt target.txt  -> fails\n// after\nlet ref_path = \"missing_ref.txt\";\nif !std::path::Path::new(ref_path).exists() {\n    // fall back to an explicit date\n    // touch -d \"2026-01-01 00:00\" target.txt\n}","handlingStrategy":"validation","validationCode":"fn validate_reference(path: &std::path::Path) -> Result<(), String> {\n    match std::fs::metadata(path) {\n        Ok(_) => Ok(()),\n        Err(e) => Err(format!(\"reference '{}' inaccessible: {}\", path.display(), e)),\n    }\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(TouchError::ReferenceFileInaccessible(path, io)) => {\n        eprintln!(\"reference {} failed: {} — falling back to explicit date\", path.display(), io);\n        // proceed with -d explicit timestamp\n    }\n    other => other.map(|_| ()),\n}","preventionTips":["Always stat the -r reference path before invoking touch","Use absolute paths for reference files in scripts","Prefer -d/-t explicit dates when the reference may be ephemeral","Quote paths with spaces in shell wrappers"],"tags":["filesystem","io","touch","reference-file"],"backgroundTag":"file-not-found","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}