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

  1. Keep the default in exactly one place: remove it from the schema tag or delete the InputField.Default supplement.
  2. 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

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


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/9573a6d8804a8cb1. Report an issue: GitHub.