larksuite/cli · error
schema token %q is duplicated
Error message
schema token %q is duplicated
What it means
Thrown by parseSchemaTag when the same schema token key appears more than once in the tag. Duplicate keys would make constraint precedence ambiguous, so the parser tracks seen keys and rejects repeats.
Source
Thrown at shortcuts/common/typed_compile_args.go:409
}
func schemaHasShapeConstraints(schema schemaTag) bool {
return len(schema.enum) > 0 || schema.format != "" || hasStringConstraints(schema) || hasNumberConstraints(schema) || hasItemConstraints(schema)
}
func parseSchemaTag(raw string, valueType reflect.Type, input bool) (schemaTag, error) {
var result schemaTag
if raw == "" {
return result, fmt.Errorf("schema tag must declare exactly one of required or optional")
}
seen := make(map[string]struct{})
for _, token := range strings.Split(raw, ";") {
if token == "" || token != strings.TrimSpace(token) {
return result, fmt.Errorf("schema contains blank or untrimmed token %q", token)
}
key, value, hasValue := strings.Cut(token, "=")
if _, duplicate := seen[key]; duplicate {
return result, fmt.Errorf("schema token %q is duplicated", key)
}
seen[key] = struct{}{}
switch key {
case "required":
if hasValue {
return result, fmt.Errorf("schema token required does not accept a value")
}
result.required = true
case "optional":
if hasValue {
return result, fmt.Errorf("schema token optional does not accept a value")
}
result.optional = true
case "nullable", "nonnullable":
if hasValue {
return result, fmt.Errorf("schema token %s does not accept a value", key)
}
if result.nullable != nil {View on GitHub (pinned to 7fd6ef3c07)
Solutions
- Remove the duplicate token
- Merge repeated value tokens into one (e.g. `enum=a,b` instead of two enum tokens)
- Keep each key at most once per schema tag
Example fix
// before Name string `cli:"--name;schema:\"required;enum=a;enum=b\""` // after Name string `cli:"--name;schema:\"required;enum=a,b\""`
Defensive patterns
Strategy: validation
Validate before calling
seen := map[string]bool{}
for _, tok := range strings.Split(tag, ";") {
key, _, _ := strings.Cut(tok, "=")
if seen[key] { return fmt.Errorf("duplicate schema token %q", key) }
seen[key] = true
} Prevention
- Merge repeated value tokens (enum=a;enum=b -> enum=a,b)
- Review merge-conflict resolutions in struct tag lines
- Enforce one-key-per-tag in a lint rule
When it happens
Trigger: A tag like `schema:"required;required"` or `"enum=a;enum=b"` — after strings.Cut, the key is found in the seen map.
Common situations: Appending a second value to a token without merging it (e.g. two enum tokens instead of one comma-separated value); merge conflicts concatenating both halves of an edited tag.
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
- schema tag must declare exactly one of required or optional
- schema contains blank or untrimmed token %q
- schema token required does not accept a value
- schema token optional does not accept a value
- schema token %s does not accept a value
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/9b0f961adf71da48.
Report an issue: GitHub.