larksuite/cli · error

Shape conflicts with schema constraints or nullable declarat

Error message

Shape conflicts with schema constraints or nullable declaration

What it means

Like error 604 but in mergeInputSupplement: when InputField.Shape is supplied programmatically, the compiled field must not already carry shape constraints from its schema tag (enum, format, string/number/item bounds) or a nullable/nonnullable declaration. Both would define conflicting value shapes.

Source

Thrown at shortcuts/common/typed_compile_args.go:212

		return nil, nil, false, fmt.Errorf("Provided type has no Value field")
	}
	set, ok := t.FieldByName("Set")
	if !ok || set.Type.Kind() != reflect.Bool {
		return nil, nil, false, fmt.Errorf("Provided type has invalid Set field")
	}
	return value.Type, value.Index, true, nil
}

func mergeInputSupplement(field *compiledInputField, supplement typedInputField) error {
	if supplement.Description != "" {
		if field.description != "" {
			return fmt.Errorf("description is declared by both doc and InputField.Description")
		}
		field.description = strings.TrimSpace(supplement.Description)
	}
	if supplement.Shape != nil {
		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")
		}

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Strip the constraint tokens (enum, format, minLength/maxLength, minimum/maximum, minItems/maxItems, nullable/nonnullable) from the schema tag, keeping only required/optional.
  2. Alternatively drop InputField.Shape and keep the constraints in the tag.
  3. Keep default declarations in exactly one place as well to avoid the related duplicate-default error.

Example fix

// before
Count int `flag:"count" schema:"optional;minimum=1"`
// plus InputField{Name:"count", Shape: IntegerShape{Minimum: 1}}
// after
Count int `flag:"count" schema:"optional" doc:"Item count"`
// constraints live only in InputField.Shape
Defensive patterns

Strategy: validation

Validate before calling

if inputField.Shape != nil && (schemaHasConstraints(field.Tag.Get("schema")) || strings.Contains(field.Tag.Get("schema"), "nullable")) {
	return fmt.Errorf("flag %s: remove schema constraints/nullable before setting InputField.Shape", flagName)
}

Prevention

When it happens

Trigger: Args field `Count int \`flag:"count" schema:"optional;minimum=1"\`` combined with InputField{Name:"count", Shape: IntegerShape{...}}; also triggered when nullable is declared in the tag while Shape is passed.

Common situations: Moving validation from tags to InputField.Shape incrementally; two developers independently adding the same constraint in tag and code.

Related errors


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