{"record":{"id":"fd79948240ceba89","repo":"can1357/oh-my-pi","slug":"getfinalpathnamebyhandlew-failed-with-code-0","errorCode":null,"errorMessage":"GetFinalPathNameByHandleW failed with code {0}","messagePattern":"GetFinalPathNameByHandleW failed with code (.+?)","errorType":"error_code","errorClass":"TouchError","httpStatus":null,"severity":"error","filePath":"crates/pi-builtins/src/touch.rs","lineNumber":48,"sourceCode":"#[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 {\n\t\terror.to_string()\n\t}\n}","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/crates/pi-builtins/src/touch.rs#L30-L66","documentation":"TouchError::WindowsStdoutPathError is raised only on Windows when the Win32 call GetFinalPathNameByHandleW fails while resolving the final path of an open handle (used by touch's Windows path resolution). The error string carries the GetLastError code. This indicates the OS refused or could not complete final-path resolution for the handle.","triggerScenarios":"On Windows, calling touch code paths that resolve a handle's final path when the handle is invalid, the volume doesn't support the call, the path was deleted mid-operation, or access is denied (non-zero Win32 error code).","commonSituations":"Touching files on exotic filesystems/network drives that don't support handle-based final path resolution; race where the target file was removed by another process; running with restricted token privileges on Windows.","solutions":["Check the Win32 code in the message and look it up (e.g. ERROR_ACCESS_DENIED=5, ERROR_INVALID_HANDLE=6)","Retry after confirming the target file still exists and is not locked by another process","Run from a process with sufficient privileges for the target location","If on a network/unsupported filesystem, operate on a local path or use path-based (not handle-based) APIs"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// Windows-only: confirm target exists and process can open it before touch\n#[cfg(windows)]\nfn validate_target_windows(path: &std::path::Path) -> Result<(), String> {\n    std::fs::metadata(path).map(|_| ()).map_err(|e| e.to_string())\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(TouchError::WindowsStdoutPathError(code)) if code == \"5\" => {\n        // ERROR_ACCESS_DENIED: retry elevated or skip path\n    }\n    Err(TouchError::WindowsStdoutPathError(code)) => {\n        eprintln!(\"final-path resolution failed (code {code}); retrying once\");\n    }\n    other => other.map(|_| ()),\n}","preventionTips":["Avoid touching files on network/exotic filesystems where handle resolution is unsupported","Hold the file open (don't let another process delete it) during the operation","Run with sufficient privileges for the target directory","Retry once on transient Win32 errors before giving up"],"tags":["windows","win32","filesystem","touch"],"backgroundTag":"win32-api-call-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}