larksuite/cli · error
default is declared by both schema and InputField.Default
Error message
default is declared by both schema and InputField.Default
What it means
A default value was supplied in two places for one flag: the schema tag on the Args struct field (schema:"...,default=...") and InputField.Default. The library forbids ambiguity so the effective default is never uncertain.
Source
Thrown at shortcuts/common/typed_compile_args.go:229
if shapeHasConstraints(field.shape) || field.nullable != nil {
return fmt.Errorf("Shape conflicts with schema constraints or nullable declaration")
}
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...)
}View on GitHub (pinned to 7fd6ef3c07)
Solutions
- Keep the default in exactly one place: remove it from the schema tag or delete the InputField.Default supplement.
- If programmatic control is needed, strip default= from the schema tag and keep only InputField.Default.
Example fix
// before
Limit int `flag:"limit" schema:"default=10"` + InputField{Name: "limit", Default: ...}
// after
Limit int `flag:"limit"` + InputField{Name: "limit", Default: ...} Defensive patterns
Strategy: validation
Validate before calling
for _, f := range fields {
if f.SchemaDefault != nil && f.InputDefault.Set {
return fmt.Errorf("flag %s: default declared twice", f.Name)
}
} Prevention
- Pick one declaration channel per flag (tags OR InputField) per property and stick to it.
- Grep the codebase for existing default= tags before adding InputField.Default.
- Compile command sets in CI tests to catch conflicts immediately.
When it happens
Trigger: compileInput -> mergeInputSupplement when supplement.Default.Set is true and the field's schema-parsed defaultValue is already Set.
Common situations: Adding an InputField.Default supplement to a field that already carries a default= entry in its schema tag, or vice versa after duplicating declarations during a refactor.
Related errors
- required input cannot declare a default
- 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
- CLI.Hidden is declared twice
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/9573a6d8804a8cb1.
Report an issue: GitHub.