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 content

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Verify the file has content: cat/wc -c the path before running the command
  2. Regenerate or fix the payload file
  3. 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

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


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/d2815dc46b8ba00e. Report an issue: GitHub.