larksuite/cli · error
file %q is empty
Error message
file %q is empty
What it means
ResolveInput received a `@path` argument, read the file successfully via FileIO, but after TrimSpace the content is empty - an explicit emptiness guard so callers do not forward a blank value downstream.
Source
Thrown at internal/cmdutil/resolve.go:65
// escape: @@... → literal @... (no file read)
if strings.HasPrefix(raw, "@@") {
return raw[1:], nil
}
// file: @path
if strings.HasPrefix(raw, "@") {
path := strings.TrimSpace(raw[1:])
if path == "" {
return "", fmt.Errorf("file path cannot be empty after @")
}
data, err := ReadInputFile(fileIO, path)
if err != nil {
return "", err
}
s := strings.TrimSpace(string(data))
if s == "" {
return "", fmt.Errorf("file %q is empty", path)
}
return s, nil
}
// strip surrounding single quotes (Windows cmd.exe passes them literally)
if len(raw) >= 2 && raw[0] == '\'' && raw[len(raw)-1] == '\'' {
raw = raw[1 : len(raw)-1]
}
return raw, nil
}
// ReadInputFile reads path through fileIO. Open/read failures are wrapped with
// path context; fileio.ErrPathValidation remains matchable with errors.Is.
// All paths go through the caller's fileIO provider and its relative-to-cwd
// policy — no absolute-path side door: a trust root defined by the process
// environment (TMPDIR) is not a security boundary, and reading outside the
// provider would break sidecar/custom-FileIO ownership. Out-of-tree contentView on GitHub (pinned to 7fd6ef3c07)
Solutions
- Verify the file has content: cat/wc -c the path before running the command
- Regenerate or fix the payload file
- Point @ at the correct file path
Example fix
// before
cat prod.json # empty
lark-cli cmd --body @prod.json
// after
printf '%s' '{"k":"v"}' > prod.json
lark-cli cmd --body @prod.json Defensive patterns
Strategy: validation
Validate before calling
# shell
[ -s payload.json ] || { echo "payload.json is empty"; exit 1; }
# Go:
data, _ := fileIO.ReadFile(path); if len(bytes.TrimSpace(data)) == 0 { /* reject */ } Try / catch
if err != nil && strings.Contains(err.Error(), "is empty") {
fmt.Fprintln(os.Stderr, "hint: regenerate the payload file before running")
} Prevention
- Check file size with wc -c / [ -s ] before referencing it
- Regenerate payloads atomically (write temp + rename)
- Confirm redirect producers did not truncate the file
- Point @ at the intended file, not a placeholder
When it happens
Trigger: Calling ParseOptionalBody/ParseJSONMap with --body @path where the file exists, opens, but contains only whitespace/newlines or is zero bytes.
Common situations: Editor created an empty placeholder file; a failed redirect ("> payload.json" with a failing producer) truncated the file; wrong file selected; JSON payload written only after the command was launched.
Related errors
- file path cannot be empty after @
- --header-scan-rows must be at least 1
- +csv-get truncated the requested range at {source_range}; na
- Pass exactly one of --url or --spreadsheet-token
- Pass only one of --sheet-id or --sheet-name
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/d2815dc46b8ba00e.
Report an issue: GitHub.