mislav/hub · error

no such file in gist

Error message

no such file in gist

What it means

`getGist` was given an explicit filename that does not exist in the fetched gist's `Files` map. The gist itself is valid and reachable; only the file key lookup failed. File names are case-sensitive and must match exactly as stored on GitHub.

Source

Thrown at commands/gist.go:99

	gist, err := gh.FetchGist(id)
	if err != nil {
		return err
	}

	if len(gist.Files) > 1 && filename == "" {
		filenames := []string{}
		for name := range gist.Files {
			filenames = append(filenames, name)
		}
		sort.Strings(filenames)
		return fmt.Errorf("This gist contains multiple files, you must specify one:\n  %s", strings.Join(filenames, "\n  "))
	}

	if filename != "" {
		if val, ok := gist.Files[filename]; ok {
			ui.Println(val.Content)
		} else {
			return fmt.Errorf("no such file in gist")
		}
	} else {
		for name := range gist.Files {
			file := gist.Files[name]
			ui.Println(file.Content)
		}
	}
	return nil
}

func printGistHelp(command *Command, args *Args) {
	utils.Check(command.UsageError(""))
}

func createGist(cmd *Command, args *Args) {
	args.NoForward()

	host, err := github.CurrentConfig().DefaultHostNoPrompt()

View on GitHub (pinned to 5c547ed804)

Solutions

  1. Run `gh gist view <gist-id>` without a filename to see the exact list of file names, then use one verbatim.
  2. Check spelling and case — file keys are case-sensitive, including the extension.
  3. Re-fetch the gist to confirm the file still exists; it may have been edited/deleted.

Example fix

// before
gh gist view abc123 readme.md   # actual file is README.md
// after
gh gist view abc123 README.md
Defensive patterns

Strategy: validation

Validate before calling

gist := fetchGist(gistID)
if _, ok := gist.Files[filename]; !ok {
    fmt.Printf("available files: ")
    for name := range gist.Files {
        fmt.Printf("%s ", name)
    }
    fmt.Println()
    os.Exit(1)
}

Type guard

func fileInGist(gist *github.Gist, name string) bool {
    _, ok := gist.Files[name]
    return ok
}

Prevention

When it happens

Trigger: Running `gh gist view <gist-id> <filename>` (showGist -> getGist) where `gist.Files[filename]` is absent — typo, wrong case, missing extension, or file deleted from the gist.

Common situations: Typos or case mismatch (README.md vs readme.md); omitting the file extension; the file was removed from the gist after the command/script was written; copy-pasting a name from a different gist.

Related errors


AI-assisted analysis of mislav/hub@5c547ed804 (2026-09-01). Data as JSON: /api/errors/cabbf540aa0addae. Report an issue: GitHub.