mislav/hub · error

missing user

Error message

missing user

What it means

During PromptForHost, when the existing config entry for the host has no user (a config written by an old broken hub version, issue #1007), hub tries to fix it by prompting for a user. If the prompt yields an empty string, utils.Check panics/exits with this error. It indicates an unrepairable interactive-prompt situation (typically non-interactive stdin).

Source

Thrown at github/config.go:62

	tokenFromEnv := token != ""

	if host != GitHubHost {
		if _, e := url.Parse("https://" + host); e != nil {
			err = fmt.Errorf("invalid hostname: %q", host)
			return
		}
	}

	h = c.Find(host)
	if h != nil {
		if h.User == "" {
			utils.Check(CheckWriteable(configsFile()))
			// User is missing from the config: this is a broken config probably
			// because it was created with an old (broken) version of hub. Let's fix
			// it now. See issue #1007 for details.
			user := c.PromptForUser(host)
			if user == "" {
				utils.Check(fmt.Errorf("missing user"))
			}
			h.User = user
			err := newConfigService().Save(configsFile(), c)
			utils.Check(err)
		}
		if tokenFromEnv {
			h.AccessToken = token
		} else {
			return
		}
	} else {
		h = &Host{
			Host:        host,
			AccessToken: token,
			Protocol:    "https",
		}
		c.Hosts = append(c.Hosts, h)
	}

View on GitHub (pinned to 5c547ed804)

Solutions

  1. Manually add the `user: <username>` line under the host entry in ~/.config/hub.
  2. Delete the broken host entry from ~/.config/hub and re-run hub interactively to regenerate it.
  3. Ensure the command runs with an interactive TTY, or provide the username via stdin when scripting.
  4. Upgrade hub so configs are written correctly going forward.

Example fix

// before (~/.config/hub)
github.com:
- oauth_token: xxxx
// after
github.com:
- user: octocat
  oauth_token: xxxx
Defensive patterns

Strategy: validation

Validate before calling

cfg, _ := hub.Config()
host := cfg.Find("github.com")
if host != nil && host.User == "" {
    // repair the config before running commands
    host.User = os.Getenv("GITHUB_USER")
    err := newConfigService().Save(configsFile(), cfg)
    if err != nil { log.Fatal(err) }
}

Try / catch

defer func() {
    if r := recover(); r != nil {
        if fmt.Sprint(r) == "missing user" {
            fmt.Fprintln(os.Stderr, "Add `user: <name>` to ~/.config/hub or run hub interactively")
            os.Exit(1)
        }
        panic(r)
    }
}()

Prevention

When it happens

Trigger: PromptForHost loads an existing host entry whose User field is empty, calls PromptForUser, and the user's answer is empty (e.g. piped/empty stdin in scripts or CI).

Common situations: Legacy ~/.config/hub files migrated from old hub versions lacking a user line; running hub in CI where stdin provides no input; user just pressing Enter at the username prompt.

Related errors


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