larksuite/cli · error
invalid file path %q: %w
Error message
invalid file path %q: %w
What it means
wrapInputFileError maps a fileio.ErrPathValidation failure from FileIO.Open into "invalid file path %q: %w", preserving the cause. It indicates the path failed validation (e.g. outside allowed roots, illegal characters, traversal) before any file was opened.
Source
Thrown at internal/cmdutil/resolve.go:103
func ReadInputFile(fileIO fileio.FileIO, path string) ([]byte, error) {
if fileIO == nil {
return nil, fmt.Errorf("file input is not available in this context")
}
f, err := fileIO.Open(path)
if err != nil {
return nil, wrapInputFileError(path, err)
}
defer f.Close()
data, err := io.ReadAll(f)
if err != nil {
return nil, wrapInputFileError(path, err)
}
return data, nil
}
func wrapInputFileError(path string, err error) error {
if errors.Is(err, fileio.ErrPathValidation) {
return fmt.Errorf("invalid file path %q: %w", path, err)
}
return fmt.Errorf("cannot read file %q: %w", path, err)
}
View on GitHub (pinned to 7fd6ef3c07)
Solutions
- Use a path inside the validated workspace root (relative to the FileIO scope)
- Resolve via runtime.ValidatePath()/runtime.ResolveSavePath() before referencing the file
- Copy the file into the workspace tree first, then reference it
- Pipe content via stdin ("-") when the file lives outside the trust root
Example fix
// before lark-cli cmd --body @/etc/payload.json // after cp /etc/payload.json ./payload.json lark-cli cmd --body @payload.json
Defensive patterns
Strategy: validation
Validate before calling
// pre-validate with the runtime before using @path:
if err := rt.ValidatePath(path); err != nil { /* use stdin or a workspace-relative path */ } Try / catch
var pv *fileio.PathError
if err != nil && errors.As(err, &pv) {
fmt.Fprintf(os.Stderr, "path %q rejected: %v; use a workspace-relative path\n", path, err)
} Prevention
- Resolve paths via runtime.ValidatePath()/ResolveSavePath() before referencing
- Keep referenced files inside the workspace/trust root
- Avoid absolute paths and ../ traversal in scripts
- Copy out-of-tree files into the workspace first
When it happens
Trigger: Using --body @path where path is rejected by fileio path validation: absolute paths outside workspace roots, ../ traversal escaping the trust root, or other invalid path shapes.
Common situations: Referencing files outside the workspace/sidecar root; symlink or .. traversal attempts; Windows vs POSIX path confusion; migrating scripts that used absolute host paths into the scoped FileIO model.
Related errors
- file input is not available in this context
- cannot read file %q: %w
- %s: %w
- path validation failed
- %s: path must be absolute, got %q
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/ee0401f39883dbe0.
Report an issue: GitHub.