larksuite/cli · error

%s field %s (%s): Data field cannot declare default

Error message

%s field %s (%s): Data field cannot declare default

What it means

The `schema:` tag declared a default value on a field of an output/Data struct (compiled with input=false). Defaults only make sense for input values the caller may omit; output data always carries concrete values, so the compiler rejects defaults there.

Source

Thrown at shortcuts/common/typed_compile_data.go:232

		for _, option := range parts[1:] {
			switch option {
			case "omitempty":
				omitempty = true
			case "":
			default:
				return typedObjectShape{}, fmt.Errorf("%s field %s has unsupported json option %q", path, field.Name, option)
			}
		}
		if previous, exists := seen[name]; exists {
			return typedObjectShape{}, fmt.Errorf("%s field %s JSON name %q duplicates field %s", path, field.Name, name, previous)
		}
		seen[name] = field.Name
		schema, err := parseSchemaTag(field.Tag.Get("schema"), field.Type, input)
		if err != nil {
			return typedObjectShape{}, fmt.Errorf("%s field %s (%s): %w", path, field.Name, name, err)
		}
		if !input && schema.defaultValue.Set {
			return typedObjectShape{}, fmt.Errorf("%s field %s (%s): Data field cannot declare default", path, field.Name, name)
		}
		if schema.required && omitempty {
			return typedObjectShape{}, fmt.Errorf("%s field %s (%s): required Data field cannot use omitempty", path, field.Name, name)
		}
		if schema.optional && !omitempty {
			return typedObjectShape{}, fmt.Errorf("%s field %s (%s): optional Data field must use omitempty", path, field.Name, name)
		}
		if isNilCapable(field.Type) && schema.nullable == nil {
			return typedObjectShape{}, fmt.Errorf("%s field %s (%s): nil-capable field must declare nullable or nonnullable", path, field.Name, name)
		}
		description := strings.TrimSpace(field.Tag.Get("doc"))
		if input && description == "" {
			return typedObjectShape{}, fmt.Errorf("%s field %s (%s): description is required via doc", path, field.Name, name)
		}
		fieldShape, err := shapeForType(field.Type, schema, input, active)
		if err != nil {
			return typedObjectShape{}, fmt.Errorf("%s field %s (%s): %w", path, field.Name, name, err)
		}

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Remove the `default=...` option from the Data struct field's schema tag
  2. If a default is genuinely needed, move the field (or struct) to the Input type definition
  3. Document the typical value in the `doc:` tag instead

Example fix

// before
// Data struct field
Retries int `json:"retries" schema:"default=3" doc:"..."`
// after
Retries int `json:"retries" schema:"required" doc:"..."`
Defensive patterns

Strategy: validation

Validate before calling

// ensure no default= appears on Data struct fields
if strings.Contains(f.Tag.Get("schema"), "default=") && !isInput {
    return fmt.Errorf("field %s: defaults only allowed on Input", f.Name)
}

Prevention

When it happens

Trigger: Compiling a Data (output) struct where a field's `schema:` tag contains a `default=...` option, e.g. `schema:"default=10"` on an output field.

Common situations: Copy-pasting field definitions between Input and Data structs; adding defaults 'for documentation' purposes on output types; refactoring a shared struct to be used both as input and output.

Related errors


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