{"record":{"id":"d2815dc46b8ba00e","repo":"larksuite/cli","slug":"file-q-is-empty","errorCode":null,"errorMessage":"file %q is empty","messagePattern":"file %q is empty","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmdutil/resolve.go","lineNumber":65,"sourceCode":"\n\t// escape: @@... → literal @... (no file read)\n\tif strings.HasPrefix(raw, \"@@\") {\n\t\treturn raw[1:], nil\n\t}\n\n\t// file: @path\n\tif strings.HasPrefix(raw, \"@\") {\n\t\tpath := strings.TrimSpace(raw[1:])\n\t\tif path == \"\" {\n\t\t\treturn \"\", fmt.Errorf(\"file path cannot be empty after @\")\n\t\t}\n\t\tdata, err := ReadInputFile(fileIO, path)\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t\ts := strings.TrimSpace(string(data))\n\t\tif s == \"\" {\n\t\t\treturn \"\", fmt.Errorf(\"file %q is empty\", path)\n\t\t}\n\t\treturn s, nil\n\t}\n\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","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/cmdutil/resolve.go#L47-L83","documentation":"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.","triggerScenarios":"Calling ParseOptionalBody/ParseJSONMap with --body @path where the file exists, opens, but contains only whitespace/newlines or is zero bytes.","commonSituations":"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.","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"],"exampleFix":"// before\ncat prod.json   # empty\nlark-cli cmd --body @prod.json\n// after\nprintf '%s' '{\"k\":\"v\"}' > prod.json\nlark-cli cmd --body @prod.json","handlingStrategy":"validation","validationCode":"# shell\n[ -s payload.json ] || { echo \"payload.json is empty\"; exit 1; }\n# Go:\ndata, _ := fileIO.ReadFile(path); if len(bytes.TrimSpace(data)) == 0 { /* reject */ }","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"is empty\") {\n    fmt.Fprintln(os.Stderr, \"hint: regenerate the payload file before running\")\n}","preventionTips":["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"],"tags":["file-input","empty-file","cli"],"backgroundTag":"empty-input-file","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"}