mislav/hub · error

property name is must be string but got %#v

Error message

property name is must be string but got %#v

What it means

Within a host's property MapSlice, every property key must be a string to be matched against known fields (user, oauth_token, protocol, unix_socket). A non-string key fails the type assertion and Decode returns this error naming the offending key.

Source

Thrown at github/config_decoder.go:56

	}

	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":
				host.AccessToken, ok = prop.Value.(string)
			case "protocol":
				host.Protocol, ok = prop.Value.(string)
			case "unix_socket":
				host.UnixSocket, ok = prop.Value.(string)
			}
			if !ok {
				return fmt.Errorf("%s is must be string but got %#v", propName, prop.Value)
			}
		}
		c.Hosts = append(c.Hosts, host)
	}

View on GitHub (pinned to 5c547ed804)

Solutions

  1. Ensure all property keys under each host are plain string keys (user, oauth_token, protocol, unix_socket).
  2. Quote ambiguous keys and remove non-property entries from the host list.
  3. Regenerate ~/.config/hub via interactive hub login if the file is corrupted.

Example fix

// before
github.com:
- user: octocat
  2023: junk
// after
github.com:
- user: octocat
  oauth_token: xxxx
Defensive patterns

Strategy: validation

Validate before calling

var raw map[string][]interface{}
yaml.Unmarshal(data, &raw)
for _, entries := range raw {
    for _, e := range entries {
        m, ok := e.(yaml.MapSlice)
        if !ok { continue }
        for _, p := range m {
            if _, ok := p.Key.(string); !ok {
                log.Fatalf("property key %v is not a string", p.Key)
            }
        }
    }
}

Type guard

func isStringPropKey(k interface{}) bool {
    _, ok := k.(string)
    return ok
}

Try / catch

if err := cfg.Decode(data); err != nil {
    if strings.Contains(err.Error(), "property name is must be string") {
        return fmt.Errorf("non-string property key in hub config: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: A property inside a host entry whose key is a numeric, boolean, or null YAML scalar instead of a string, e.g. `- 123: value` under a host.

Common situations: Corrupted or hand-mangled config files; paste errors adding junk lines; unquoted keys parsed by YAML as non-string scalars.

Related errors


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