larksuite/cli · error
required input cannot declare default
Error message
required input cannot declare default
What it means
A field marked `required` in its schema tag cannot also declare a `default` value. A required input must always be supplied by the caller, so a default would be unreachable and signals a contradiction; parseSchemaTag rejects this combination at compile time.
Source
Thrown at shortcuts/common/typed_compile_args.go:498
if err != nil {
return result, fmt.Errorf("schema minItems: %w", err)
}
result.minItems = &v
case "maxItems":
v, err := parseNonnegativeInt(value)
if err != nil {
return result, fmt.Errorf("schema maxItems: %w", err)
}
result.maxItems = &v
default:
return result, fmt.Errorf("unknown schema token %q", key)
}
}
if result.required == result.optional {
return result, fmt.Errorf("schema must declare exactly one of required or optional")
}
if result.required && result.defaultValue.Set {
return result, fmt.Errorf("required input cannot declare default")
}
if result.nullable != nil && *result.nullable && !isNilCapable(valueType) {
return result, fmt.Errorf("nullable requires a nil-capable Go type")
}
if result.minLength != nil && result.maxLength != nil && *result.minLength > *result.maxLength {
return result, fmt.Errorf("minLength exceeds maxLength")
}
if result.minimum != nil && result.maximum != nil && *result.minimum > *result.maximum {
return result, fmt.Errorf("minimum exceeds maximum")
}
if result.minItems != nil && result.maxItems != nil && *result.minItems > *result.maxItems {
return result, fmt.Errorf("minItems exceeds maxItems")
}
return result, nil
}
func parseCLITag(raw string) (typedCLIInput, error) {
var result typedCLIInputView on GitHub (pinned to 7fd6ef3c07)
Solutions
- If callers may omit the field, change required to optional and keep the default.
- If the field must be provided, remove the default token.
- Review the field's intent: a default implies optionality.
Example fix
// before Locale string `schema:"required;default=\"en-US\""` // after Locale string `schema:"optional;default=\"en-US\""`
Defensive patterns
Strategy: validation
Validate before calling
func requiredHasNoDefault(tag string) bool {
required, hasDefault := false, false
for _, tok := range strings.Split(tag, ";") {
if k, _, _ := strings.Cut(tok, "="); k == "required" {
required = true
}
if strings.HasPrefix(tok, "default=") {
hasDefault = true
}
}
return !(required && hasDefault)
} Prevention
- Treat a default value as implying `optional`.
- When adding `required`, remove any default token in the same change.
- Document field intent: required means caller must always supply it.
When it happens
Trigger: A tag like schema:"required;default=\"x\"" on an input struct field compiled via collectArgFields.
Common situations: Changing a field from optional to required while leaving its default in place, or adding required to a field that was designed with a fallback value.
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 minItems: %w
- schema maxItems: %w
- unknown schema token %q
- schema must declare exactly one of required or optional
- nullable requires a nil-capable Go type
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/8ff22fad71673b93.
Report an issue: GitHub.