larksuite/cli · error
%s %q is not a valid path on this platform
Error message
%s %q is not a valid path on this platform
What it means
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.
Source
Thrown at internal/vfs/localfileio/path.go:277
if err != nil {
return "", fmt.Errorf("cannot expand ~: %w", err)
}
p = filepath.Join(home, strings.TrimPrefix(p, "~"))
}
if !filepath.IsAbs(p) {
p = filepath.Join(cwd, p)
}
return filepath.Clean(p), nil
}
// rejectForeignAbsolute refuses a path that is absolute only under another
// platform's rules. The strict tier rejects the shape outright rather than
// silently treating it as a relative name, which is a confusing way to grant
// access; the relaxed tier keeps such paths verbatim by contract and instead
// gets the denylist applied to the location the OS would really open.
func rejectForeignAbsolute(raw, flagName string) error {
if isAbsolutePath(raw) && !filepath.IsAbs(raw) {
return fmt.Errorf("%s %q is not a valid path on this platform", flagName, raw)
}
return nil
}
// resolveReal canonicalizes abs fail-closed: an existing target resolves
// through EvalSymlinks; a missing target (output files that do not exist yet)
// resolves through the nearest existing ancestor; any other Lstat failure is
// an error — the policy never guesses when the filesystem cannot be
// inspected. ENOTDIR counts as missing: a component of the path is a regular
// file, so the target cannot exist and the write layer will surface the real
// error with proper typing.
func resolveReal(abs string) (string, error) {
_, lerr := vfs.Lstat(abs)
switch {
case lerr == nil:
resolved, err := filepath.EvalSymlinks(abs)
if err != nil {
return "", fmt.Errorf("cannot resolve symlinks: %w", err)View on GitHub (pinned to 7fd6ef3c07)
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.
Example fix
// before (on Linux) lark-cli drive upload --file 'C:\Users\alice\report.pdf' // after lark-cli drive upload --file /mnt/c/Users/alice/report.pdf
Defensive patterns
Strategy: validation
Validate before calling
// Go: detect Windows-style paths on non-Windows platforms
func isForeignAbsolute(p string) bool {
if runtime.GOOS == "windows" {
return false
}
if strings.HasPrefix(p, "\\") {
return true
}
return len(p) >= 3 && p[1] == ':' && (p[2] == '/' || p[2] == '\\')
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- %s: path must be absolute, got %q
- %s: path %q is a directory, not a file
- %q has invalid relative path %q
- %s %q resolves outside the current working directory (hint:
- cannot expand ~: %w
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/c7d1f8f2a9880855.
Report an issue: GitHub.