larksuite/cli · error
required input cannot declare a default
Error message
required input cannot declare a default
What it means
mergeInputSupplement rejects an InputField.Default on a field whose schema tag marks it required (schema:"required"). A required input must always be explicitly provided, so a default is contradictory.
Source
Thrown at shortcuts/common/typed_compile_args.go:232
shape, err := lowerAuthoringShape(supplement.Shape)
if err != nil {
return err
}
if err := validateShape(shape, "InputField.Shape"); err != nil {
return err
}
if !shapeCompatibleWithType(shape, field.valueType) {
return fmt.Errorf("InputField.Shape %T is incompatible with Go type %s", supplement.Shape, field.valueType)
}
field.shape = shape
field.shapeExplicit = true
}
if supplement.Default.Set {
if field.defaultValue.Set {
return fmt.Errorf("default is declared by both schema and InputField.Default")
}
if field.required {
return fmt.Errorf("required input cannot declare a default")
}
field.defaultValue = supplement.Default
}
if len(supplement.CLI.Aliases) > 0 {
if len(field.cli.Aliases) > 0 {
return fmt.Errorf("CLI.Aliases is declared by both cli tag and InputField.CLI")
}
field.cli.Aliases = append([]typedFlagAlias(nil), supplement.CLI.Aliases...)
}
if len(supplement.CLI.ValueSources) > 0 {
if len(field.cli.ValueSources) > 0 {
return fmt.Errorf("CLI.ValueSources is declared by both cli tag and InputField.CLI")
}
field.cli.ValueSources = append([]typedValueSource(nil), supplement.CLI.ValueSources...)
}
if supplement.CLI.Encoding != "" {
if field.cli.Encoding != "" {
return fmt.Errorf("CLI.Encoding is declared by both cli tag and InputField.CLI")View on GitHub (pinned to 7fd6ef3c07)
Solutions
- Drop the InputField.Default if the input truly must be provided.
- Remove required from the schema tag if a default fallback is the desired behavior.
Example fix
// before
ID string `flag:"id" schema:"required"` + InputField{Name: "id", Default: ...}
// after
ID string `flag:"id" schema:"required"` (no InputField.Default) Defensive patterns
Strategy: validation
Validate before calling
for _, f := range fields {
if f.Required && f.InputDefault.Set {
return fmt.Errorf("flag %s: required input cannot have default", f.Name)
}
} Prevention
- Treat required and default as mutually exclusive when designing flag schemas.
- Use Provided[T] fields instead of defaults for values callers must always supply.
- Document the intent (mandatory vs optional-with-fallback) next to each flag.
When it happens
Trigger: compileInput -> mergeInputSupplement when supplement.Default.Set is true and field.required (from schema tag) is true.
Common situations: Marking a flag required in the schema tag while adding a fallback default via InputField.Default to 'be safe'.
Related errors
- default is declared by both schema and InputField.Default
- InputField.Shape %T is incompatible with Go type %s
- CLI.Aliases is declared by both cli tag and InputField.CLI
- CLI.ValueSources is declared by both cli tag and InputField.
- CLI.Encoding is declared by both cli tag and InputField.CLI
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/3d7057f2a4db92fa.
Report an issue: GitHub.