{"record":{"id":"c7d1f8f2a9880855","repo":"larksuite/cli","slug":"s-q-is-not-a-valid-path-on-this-platform","errorCode":null,"errorMessage":"%s %q is not a valid path on this platform","messagePattern":"(.+?) %q is not a valid path on this platform","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/vfs/localfileio/path.go","lineNumber":277,"sourceCode":"\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"cannot expand ~: %w\", err)\n\t\t}\n\t\tp = filepath.Join(home, strings.TrimPrefix(p, \"~\"))\n\t}\n\tif !filepath.IsAbs(p) {\n\t\tp = filepath.Join(cwd, p)\n\t}\n\treturn filepath.Clean(p), nil\n}\n\n// rejectForeignAbsolute refuses a path that is absolute only under another\n// platform's rules. The strict tier rejects the shape outright rather than\n// silently treating it as a relative name, which is a confusing way to grant\n// access; the relaxed tier keeps such paths verbatim by contract and instead\n// gets the denylist applied to the location the OS would really open.\nfunc rejectForeignAbsolute(raw, flagName string) error {\n\tif isAbsolutePath(raw) && !filepath.IsAbs(raw) {\n\t\treturn fmt.Errorf(\"%s %q is not a valid path on this platform\", flagName, raw)\n\t}\n\treturn nil\n}\n\n// resolveReal canonicalizes abs fail-closed: an existing target resolves\n// through EvalSymlinks; a missing target (output files that do not exist yet)\n// resolves through the nearest existing ancestor; any other Lstat failure is\n// an error — the policy never guesses when the filesystem cannot be\n// inspected. ENOTDIR counts as missing: a component of the path is a regular\n// file, so the target cannot exist and the write layer will surface the real\n// error with proper typing.\nfunc resolveReal(abs string) (string, error) {\n\t_, lerr := vfs.Lstat(abs)\n\tswitch {\n\tcase lerr == nil:\n\t\tresolved, err := filepath.EvalSymlinks(abs)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"cannot resolve symlinks: %w\", err)","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/vfs/localfileio/path.go#L259-L295","documentation":"This error rejects a path that is absolute under a DIFFERENT platform's rules but not under the current one — e.g. `C:\\dir\\file` or `\\Windows` passed on Unix. RejectForeignAbsolute refuses the shape outright rather than silently treating it as a relative filename, because validating-then-opening at different locations would be a confusing way to grant access.","triggerScenarios":"Passing a Windows-style path (drive letter `C:/x` or backslash-rooted `\\dir`) on Linux/macOS to SafeInputPath/SafeOutputPath; config files or scripts copied from a Windows machine; cross-platform task automation.","commonSituations":"Shared shell scripts checked out on WSL/Linux that still use Windows paths; a config generated on Windows consumed on a Unix box; hard-coded paths in CI matrices running on multiple OSes.","solutions":["Convert the path to the current platform's format before passing it (on Unix: /mnt/c/... for Windows drives under WSL, or a POSIX path).","Store platform-neutral relative paths (relative to cwd) in shared configs/scripts.","Run the command on Windows if the path must remain a Windows path."],"exampleFix":"// before (on Linux)\nlark-cli drive upload --file 'C:\\Users\\alice\\report.pdf'\n// after\nlark-cli drive upload --file /mnt/c/Users/alice/report.pdf","handlingStrategy":"validation","validationCode":"// Go: detect Windows-style paths on non-Windows platforms\nfunc isForeignAbsolute(p string) bool {\n    if runtime.GOOS == \"windows\" {\n        return false\n    }\n    if strings.HasPrefix(p, \"\\\\\") {\n        return true\n    }\n    return len(p) >= 3 && p[1] == ':' && (p[2] == '/' || p[2] == '\\\\')\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never hard-code Windows paths in scripts intended to run on Linux/macOS.","In CI matrices, derive the file path from the OS (e.g. via filepath helpers) instead of sharing one literal.","For WSL, use /mnt/<drive>/... forms for Windows files."],"tags":["go","cross-platform","path-validation","windows-paths"],"backgroundTag":"foreign-path-format","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}