larksuite/cli · error

invalid identity %q: must be user|bot

Error message

invalid identity %q: must be user|bot

What it means

ParseIdentity in extension/platform only accepts "user" or "bot" (or empty, meaning unset). Any other string is rejected with this error because Identity is a closed two-value enum used to select the caller identity for API calls.

Source

Thrown at extension/platform/identity.go:29

// IDE help; raw-string boundaries (yaml, cobra annotation) cross
// through ParseIdentity.
type Identity string

const (
	IdentityUser Identity = "user"
	IdentityBot  Identity = "bot"
)

// ParseIdentity converts a raw string into an Identity. Returns
// ("", nil) for empty input ("not specified"), error for unrecognised
// values. Matching is strict (case-sensitive, no trim).
func ParseIdentity(s string) (Identity, error) {
	if s == "" {
		return "", nil
	}
	id := Identity(s)
	if id != IdentityUser && id != IdentityBot {
		return "", fmt.Errorf("invalid identity %q: must be user|bot", s)
	}
	return id, nil
}

// IsValid reports whether i is one of the two recognised values.
func (i Identity) IsValid() bool {
	return i == IdentityUser || i == IdentityBot
}

// String returns the underlying string.
func (i Identity) String() string { return string(i) }

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Use exactly "user" or "bot" (lowercase)
  2. Call Identity(s).IsValid() before relying on the parsed value
  3. Lowercase and trim the input string before parsing
  4. Leave the value empty if the identity should be inherited/unset

Example fix

// before
id, err := platform.ParseIdentity("User")
// after
id, err := platform.ParseIdentity("user")
Defensive patterns

Strategy: validation

Validate before calling

func validIdentity(s string) bool { return s == "" || s == "user" || s == "bot" }
id, err := platform.ParseIdentity(strings.ToLower(strings.TrimSpace(cfg.Identity)))

Type guard

func isIdentity(s string) bool { switch s { case "", "user", "bot": return true }; return false }

Try / catch

id, err := platform.ParseIdentity(s)
if err != nil { return fmt.Errorf("config identity: %w", err) }

Prevention

When it happens

Trigger: Calling ParseIdentity with a misspelled or differently-cased value such as "User", "USER", "application", or a config file supplying an unknown identity string.

Common situations: Hand-edited config with identity: "app"; environment variables copied from another tool's vocabulary; case-sensitivity surprises after normalizing input to uppercase.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/1cd72eb5995f590f. Report an issue: GitHub.