cli/cli · error

no file in the gist

Error message

no file in the gist

What it means

Thrown by gh gist edit when --filename was not supplied and the fetched gist's Files map contains zero entries. A gist with no files cannot have anything edited, so the file-selection logic bails out with this error.

Source

Thrown at pkg/cmd/gist/edit/edit.go:265

		return updateGist(apiClient, host, gistToUpdate)
	}

	filesToUpdate := map[string]string{}

	for {
		filename := opts.EditFilename
		candidates := []string{}
		for filename := range gistToUpdate.Files {
			candidates = append(candidates, filename)
		}

		sort.Strings(candidates)

		if filename == "" {
			if len(candidates) == 1 {
				filename = candidates[0]
			} else if len(candidates) == 0 {
				return errors.New("no file in the gist")
			} else {
				if !opts.IO.CanPrompt() {
					return errors.New("unsure what file to edit; either specify --filename or run interactively")
				}
				result, err := opts.Prompter.Select("Edit which file?", "", candidates)
				if err != nil {
					return fmt.Errorf("could not prompt: %w", err)
				}
				filename = candidates[result]
			}
		}

		gistFile, found := gistToUpdate.Files[filename]
		if !found {
			return fmt.Errorf("gist has no file %q", filename)
		}
		if shared.IsBinaryContents([]byte(gistFile.Content)) {
			return fmt.Errorf("editing binary files not supported")

View on GitHub (pinned to 0eeec0b92e)

Solutions

  1. Check the gist still has files: `gh gist view <id>` or `gh api gists/<id> --jq '.files | keys'
  2. If the gist is intentionally empty, delete and recreate it with `gh gist create` instead of editing
  3. Recreate the deleted content by adding a file: `gh gist edit <id> --filename new.txt` with content supplied appropriately
Defensive patterns

Strategy: validation

Validate before calling

count=$(gh api gists/$GIST_ID --jq '.files | length')
[ "$count" -gt 0 ] || { echo "gist has no files; recreate instead" >&2; exit 1; }

Prevention

When it happens

Trigger: Editing a gist from which every file has previously been deleted (the GitHub API allows a gist to end up with an empty file map); racing against another client that deleted the files between fetch and edit.

Common situations: Automation that deletes all files from a gist via repeated gh gist edit --remove calls and then tries a subsequent edit; gists emptied by a collaborator before your edit command runs.

Related errors


AI-assisted analysis of cli/cli@0eeec0b92e (2026-08-15). Data as JSON: /api/errors/b1bc20b2b334fb9c. Report an issue: GitHub.