mislav/hub · error

value of host entry is must be array but got %#v

Error message

value of host entry is must be array but got %#v

What it means

The custom YAML decoder for ~/.config/hub expects each top-level host entry's value to be a YAML array (list of MapSlice property blocks). If a host key maps to anything else (a scalar, a bare map), Decode returns this error describing the actual value. It protects the decoder from malformed config structures.

Source

Thrown at github/config_decoder.go:43

}

func (y *yamlConfigDecoder) Decode(r io.Reader, c *Config) error {
	d, err := ioutil.ReadAll(r)
	if err != nil {
		return err
	}

	yc := yaml.MapSlice{}
	err = yaml.Unmarshal(d, &yc)

	if err != nil {
		return err
	}

	for _, hostEntry := range yc {
		v, ok := hostEntry.Value.([]interface{})
		if !ok {
			return fmt.Errorf("value of host entry is must be array but got %#v", hostEntry.Value)
		}
		if len(v) < 1 {
			continue
		}
		hostName, ok := hostEntry.Key.(string)
		if !ok {
			return fmt.Errorf("host name is must be string but got %#v", hostEntry.Key)
		}
		host := &Host{Host: hostName}
		for _, prop := range v[0].(yaml.MapSlice) {
			propName, ok := prop.Key.(string)
			if !ok {
				return fmt.Errorf("property name is must be string but got %#v", prop.Key)
			}
			switch propName {
			case "user":
				host.User, ok = prop.Value.(string)
			case "oauth_token":

View on GitHub (pinned to 5c547ed804)

Solutions

  1. Rewrite the host entry so its value is a list of property maps: `github.com:\n- user: octocat\n oauth_token: xxxx`.
  2. Restore the file from a backup or let hub regenerate it by deleting the malformed entry.
  3. Validate the YAML structure with a linter before saving.

Example fix

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

Strategy: validation

Validate before calling

// Parse the config yourself first and check the shape:
var raw map[string]interface{}
yaml.Unmarshal(data, &raw)
for name, v := range raw {
    if _, ok := v.([]interface{}); !ok {
        log.Fatalf("host %q must map to a YAML list, got %T", name, v)
    }
}

Type guard

func isHostEntryArray(v interface{}) bool {
    _, ok := v.([]interface{})
    return ok
}

Try / catch

cfg := &github.Config{}
if err := cfg.Decode(data); err != nil {
    if strings.Contains(err.Error(), "must be array") {
        return fmt.Errorf("malformed hub config, expected list under host name: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Decoding a configs file where a host key's value is not a sequence, e.g. `github.com: octocat` or `github.com: {user: octocat}` instead of `github.com:\n- user: octocat`.

Common situations: Hand-edited hub config files; configs written by other tools with a flatter structure; YAML anchors/tags producing non-list values.

Related errors


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