{"record":{"id":"69bc726d4508b36d","repo":"larksuite/cli","slug":"file-input-is-not-available-in-this-context","errorCode":null,"errorMessage":"file input is not available in this context","messagePattern":"file input is not available in this context","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmdutil/resolve.go","lineNumber":87,"sourceCode":"\n\t// strip surrounding single quotes (Windows cmd.exe passes them literally)\n\tif len(raw) >= 2 && raw[0] == '\\'' && raw[len(raw)-1] == '\\'' {\n\t\traw = raw[1 : len(raw)-1]\n\t}\n\n\treturn raw, nil\n}\n\n// ReadInputFile reads path through fileIO. Open/read failures are wrapped with\n// path context; fileio.ErrPathValidation remains matchable with errors.Is.\n// All paths go through the caller's fileIO provider and its relative-to-cwd\n// policy — no absolute-path side door: a trust root defined by the process\n// environment (TMPDIR) is not a security boundary, and reading outside the\n// provider would break sidecar/custom-FileIO ownership. Out-of-tree content\n// reaches flags via stdin (\"-\").\nfunc ReadInputFile(fileIO fileio.FileIO, path string) ([]byte, error) {\n\tif fileIO == nil {\n\t\treturn nil, fmt.Errorf(\"file input is not available in this context\")\n\t}\n\tf, err := fileIO.Open(path)\n\tif err != nil {\n\t\treturn nil, wrapInputFileError(path, err)\n\t}\n\tdefer f.Close()\n\tdata, err := io.ReadAll(f)\n\tif err != nil {\n\t\treturn nil, wrapInputFileError(path, err)\n\t}\n\treturn data, nil\n}\n\nfunc wrapInputFileError(path string, err error) error {\n\tif errors.Is(err, fileio.ErrPathValidation) {\n\t\treturn fmt.Errorf(\"invalid file path %q: %w\", path, err)\n\t}\n\treturn fmt.Errorf(\"cannot read file %q: %w\", path, err)","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/cmdutil/resolve.go#L69-L105","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nlark-cli cmd --body @payload.json   # context without FileIO\n// after\ncat payload.json | lark-cli cmd --body -","handlingStrategy":"fallback","validationCode":null,"typeGuard":"func fileInputAvailable(rt *runtime.Context) bool { return rt != nil && rt.FileIO() != nil }","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"file input is not available\") {\n    // fallback: pipe content via stdin\n    cmd.Stdin = bytes.NewReader(payload)\n    args = append(args, \"--body\", \"-\")\n}","preventionTips":["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"],"tags":["fileio","runtime-context","file-input"],"backgroundTag":"fileio-unavailable","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}