cli/cli · error
no files passed
Error message
no files passed
What it means
Thrown by processFiles in gh gist create when the filenames slice is empty. The gist creation API requires at least one file, and this guard fires before any network call. It means the command was invoked with no positional file arguments and no stdin content routed in.
Source
Thrown at pkg/cmd/gist/create/create.go:196
}
fmt.Fprintf(errOut, "%s %s\n", cs.SuccessIconWithColor(cs.Green), completionMessage)
if opts.WebMode {
fmt.Fprintf(opts.IO.Out, "Opening %s in your browser.\n", text.DisplayURL(gist.HTMLURL))
return opts.Browser.Browse(gist.HTMLURL)
}
fmt.Fprintln(opts.IO.Out, gist.HTMLURL)
return nil
}
func processFiles(stdin io.ReadCloser, filenameOverride string, filenames []string) (map[string]*shared.GistFile, error) {
fs := map[string]*shared.GistFile{}
if len(filenames) == 0 {
return nil, errors.New("no files passed")
}
for i, f := range filenames {
var filename string
var content []byte
var err error
if f == "-" {
if filenameOverride != "" {
filename = filenameOverride
} else {
filename = fmt.Sprintf("gistfile%d.txt", i)
}
content, err = io.ReadAll(stdin)
if err != nil {
return fs, fmt.Errorf("failed to read from stdin: %w", err)
}
stdin.Close()View on GitHub (pinned to 0eeec0b92e)
Solutions
- Pass at least one filename or `-` to read from stdin: `gh gist create -` < file.txt
- In scripts, check the file list is non-empty before invoking gh: `if [ ${#files[@]} -gt 0 ]; then gh gist create "${files[@]}"; fi`
- When forwarding stdin, remember `gh gist create -` is required; bare `gh gist create` never reads stdin implicitly
Example fix
# before
gh gist create "${files[@]}"
# after
[ ${#files[@]} -gt 0 ] && gh gist create "${files[@]}" || echo "no files to gist" Defensive patterns
Strategy: validation
Validate before calling
# bash: ensure at least one file argument
files=("$@")
[ ${#files[@]} -gt 0 ] || { echo "refusing: no files to gist" >&2; exit 1; }
gh gist create "${files[@]}" Prevention
- Never invoke gh gist create with an unguarded glob; verify the array length first
- Use `gh gist create -` explicitly when feeding stdin rather than assuming implicit reads
- In wrapper functions, fail fast with a clear message when the file list is empty
When it happens
Trigger: Running `gh gist create` with zero positional arguments and no `-` (stdin) file; programmatic invocations that build an args slice from a glob or variable that evaluates to empty.
Common situations: Shell scripts where a glob like *.log matches nothing (nullglob off, it passes a literal, but with nullglob it passes nothing); CI jobs generating gists from optional artifacts; wrapping gh in a tool that forwards an empty file list.
Related errors
- file contents cannot be empty
- pull request title must not be blank
- empty workflow selector
- failed to collect files for posting: %w
- gist has no file %q
AI-assisted analysis of cli/cli@0eeec0b92e (2026-08-15).
Data as JSON: /api/errors/23741495144f89b1.
Report an issue: GitHub.