larksuite/cli · error
cannot read file %q: %w
Error message
cannot read file %q: %w
What it means
wrapInputFileError's fallback branch wraps any FileIO.Open or read error that is not ErrPathValidation as "cannot read file %q: %w". Typical causes are file-not-found, permission denied, or a read failure — the wrapped cause identifies which.
Source
Thrown at internal/cmdutil/resolve.go:105
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
- Check the wrapped cause: not-found → fix the path; permission-denied → fix permissions
- Run ls/stat on the exact path relative to the FileIO workspace root
- Create/regenerate the file before invoking the command
- Fall back to piping content via stdin ("-") if the file is inaccessible
Example fix
// before lark-cli cmd --body @paylaod.json # typo // after lark-cli cmd --body @payload.json
Defensive patterns
Strategy: try-catch
Validate before calling
# shell pre-checks
[ -e "$f" ] || { echo "missing: $f"; exit 1; }
[ -r "$f" ] || { echo "unreadable: $f"; exit 1; } Try / catch
if err != nil {
if errors.Is(err, fs.ErrNotExist) { fmt.Fprintf(os.Stderr, "no such file: %v\n", err) }
else if errors.Is(err, fs.ErrPermission) { fmt.Fprintf(os.Stderr, "permission denied: %v\n", err) }
return err
} Prevention
- Stat the file (existence + readability) before invoking
- Use stable, verified paths; avoid typos via tab-completion/variables
- Ensure sidecar containers mount the expected files
- Regenerate files in an atomic write before use
When it happens
Trigger: Using --body @path where the file does not exist, lacks read permission, or the underlying reader fails after Open. Any non-validation error from ReadInputFile's open/read path lands here.
Common situations: Typo in the filename; file deleted between generation and use; running in a sidecar/container that lacks the file; permission changes; relative path resolved against an unexpected root.
Related errors
- file input is not available in this context
- invalid file path %q: %w
- path validation failed
- failed to read secret file %s: %w
- file path cannot be empty after @
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/cc2c75beb74fe5e3.
Report an issue: GitHub.