larksuite/cli · error
file input is not available in this context
Error message
file input is not available in this context
What it means
ReadInputFile requires a non-nil fileio.FileIO provider to open @-referenced files. When the context was constructed without file input support (nil FileIO), the library refuses with this error rather than panicking. This preserves the sidecar/custom-FileIO ownership boundary: no absolute-path side door via process environment.
Source
Thrown at internal/cmdutil/resolve.go:87
// 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
// reaches flags via stdin ("-").
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 runtime context that provides FileIO (runtime.FileIO())
- Pass the content via stdin ("-") instead of @file — stdin is the documented path for out-of-tree content
- Pass the content inline as the flag value
- In tests, use a factory/context that wires a FileIO implementation
Example fix
// before lark-cli cmd --body @payload.json # context without FileIO // after cat payload.json | lark-cli cmd --body -
Defensive patterns
Strategy: fallback
Type guard
func fileInputAvailable(rt *runtime.Context) bool { return rt != nil && rt.FileIO() != nil } Try / catch
if err != nil && strings.Contains(err.Error(), "file input is not available") {
// fallback: pipe content via stdin
cmd.Stdin = bytes.NewReader(payload)
args = append(args, "--body", "-")
} Prevention
- Wire a FileIO provider into the runtime context when @file inputs are needed
- In sidecar/readonly hosts, document that stdin ("-") is the only input path
- Check runtime.FileIO() availability before generating @-style flags in automation
When it happens
Trigger: Using an @file input flag in a runtime context built without FileIO (e.g. a minimal/readonly runtime, sidecar context, or test factory lacking file support), triggering ResolveInput → ReadInputFile with fileIO == nil.
Common situations: Running a command in an embedded/plugin host that does not provide workspace file access; invoking shortcuts through a custom runtime context that omitted FileIO; out-of-tree content attempted in a sandboxed sidecar.
Related errors
- invalid file path %q: %w
- cannot read file %q: %w
- path validation failed
- file path cannot be empty after @
- file %q is empty
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/69bc726d4508b36d.
Report an issue: GitHub.