larksuite/cli · error
%s contains duplicate scope %q
Error message
%s contains duplicate scope %q
What it means
Scopes slices must not contain the same scope twice. validateScopeList tracks seen entries and fails on the first repeat, reporting the path (e.g. Authorization.user.RequiredScopes) and the duplicated scope.
Source
Thrown at shortcuts/common/typed_compiler.go:179
return fmt.Errorf("Metadata.Authorization.IdentityOrder contains undeclared identity %q", identity)
}
if _, duplicate := seen[identity]; duplicate {
return fmt.Errorf("Metadata.Authorization.IdentityOrder contains duplicate identity %q", identity)
}
seen[identity] = struct{}{}
}
}
return nil
}
func validateScopeList(scopes []string, path string) error {
seen := make(map[string]struct{}, len(scopes))
for i, scope := range scopes {
if strings.TrimSpace(scope) == "" || scope != strings.TrimSpace(scope) {
return fmt.Errorf("%s[%d] must be a non-blank trimmed scope", path, i)
}
if _, ok := seen[scope]; ok {
return fmt.Errorf("%s contains duplicate scope %q", path, scope)
}
seen[scope] = struct{}{}
}
return nil
}
func shortcutFromCompiled(compiled *compiledCommand) Shortcut {
metadata := compiled.metadata
shortcut := Shortcut{
Service: string(metadata.Service),
Command: metadata.Command,
Description: metadata.Description,
Risk: string(metadata.Risk),
Hidden: metadata.Hidden,
typed: compiled,
}
identities := make([]string, 0, len(metadata.Authorization.Identities))
identityOrder := metadata.Authorization.IdentityOrderView on GitHub (pinned to 7fd6ef3c07)
Solutions
- Remove the duplicate entry so each scope appears at most once per list
- If merging lists, deduplicate via a map or a small helper before assignment
- Check whether the scope actually belongs in RequiredScopes — a conditional scope duplicating an always-required scope also fails separately at line 141
Example fix
// before
RequiredScopes: []string{"im:message", "im:chat", "im:message"},
// after
RequiredScopes: []string{"im:message", "im:chat"}, Defensive patterns
Strategy: validation
Validate before calling
seen := map[string]bool{}
for _, s := range scopes { if seen[s] { return fmt.Errorf("duplicate scope %q", s) }; seen[s] = true } Prevention
- Deduplicate merged scope lists with a set before assignment
- Keep a single canonical scope list per identity and reference it
- Review literals for copy-paste duplicates
When it happens
Trigger: RequiredScopes or ConditionalScopes[i].Scopes lists a scope like "im:message" twice; a conditional scope duplicating another entry within the same list.
Common situations: Merging scope lists from two sources without deduplication; copy-paste duplication in a literal; appending default scopes plus explicitly repeated ones.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- %s.When must be trimmed
- %s.Requirement %q is invalid
- %s[%d] must be a non-blank trimmed scope
- Metadata.Authorization.IdentityOrder must contain each decla
- Metadata.Authorization.IdentityOrder contains undeclared ide
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/308ba0ab01cac459.
Report an issue: GitHub.