{"record":{"id":"308ba0ab01cac459","repo":"larksuite/cli","slug":"s-contains-duplicate-scope-q","errorCode":null,"errorMessage":"%s contains duplicate scope %q","messagePattern":"(.+?) contains duplicate scope %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_compiler.go","lineNumber":179,"sourceCode":"\t\t\t\treturn fmt.Errorf(\"Metadata.Authorization.IdentityOrder contains undeclared identity %q\", identity)\n\t\t\t}\n\t\t\tif _, duplicate := seen[identity]; duplicate {\n\t\t\t\treturn fmt.Errorf(\"Metadata.Authorization.IdentityOrder contains duplicate identity %q\", identity)\n\t\t\t}\n\t\t\tseen[identity] = struct{}{}\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc validateScopeList(scopes []string, path string) error {\n\tseen := make(map[string]struct{}, len(scopes))\n\tfor i, scope := range scopes {\n\t\tif strings.TrimSpace(scope) == \"\" || scope != strings.TrimSpace(scope) {\n\t\t\treturn fmt.Errorf(\"%s[%d] must be a non-blank trimmed scope\", path, i)\n\t\t}\n\t\tif _, ok := seen[scope]; ok {\n\t\t\treturn fmt.Errorf(\"%s contains duplicate scope %q\", path, scope)\n\t\t}\n\t\tseen[scope] = struct{}{}\n\t}\n\treturn nil\n}\n\nfunc shortcutFromCompiled(compiled *compiledCommand) Shortcut {\n\tmetadata := compiled.metadata\n\tshortcut := Shortcut{\n\t\tService:     string(metadata.Service),\n\t\tCommand:     metadata.Command,\n\t\tDescription: metadata.Description,\n\t\tRisk:        string(metadata.Risk),\n\t\tHidden:      metadata.Hidden,\n\t\ttyped:       compiled,\n\t}\n\tidentities := make([]string, 0, len(metadata.Authorization.Identities))\n\tidentityOrder := metadata.Authorization.IdentityOrder","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_compiler.go#L161-L197","documentation":"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.","triggerScenarios":"RequiredScopes or ConditionalScopes[i].Scopes lists a scope like \"im:message\" twice; a conditional scope duplicating another entry within the same list.","commonSituations":"Merging scope lists from two sources without deduplication; copy-paste duplication in a literal; appending default scopes plus explicitly repeated ones.","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"],"exampleFix":"// before\nRequiredScopes: []string{\"im:message\", \"im:chat\", \"im:message\"},\n// after\nRequiredScopes: []string{\"im:message\", \"im:chat\"},","handlingStrategy":"validation","validationCode":"seen := map[string]bool{}\nfor _, s := range scopes { if seen[s] { return fmt.Errorf(\"duplicate scope %q\", s) }; seen[s] = true }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["go","validation","shortcut-compiler","authorization-scopes"],"backgroundTag":"schema-validation-failed","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}