larksuite/cli · error
%s string lengths must be nonnegative
Error message
%s string lengths must be nonnegative
What it means
validateShape rejects a typedStringShape whose MinLength or MaxLength is negative. Negative length constraints are meaningless for strings and would produce an invalid JSON schema, so the compiler refuses the declaration at startup with the shape path in the message.
Source
Thrown at shortcuts/common/typed_compile_data.go:264
}
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)
}
shape.Fields = append(shape.Fields, typedValueField{Name: name, Description: description, Required: schema.required, Shape: fieldShape})
}
return shape, nil
}
func validateShape(shape typedValueShape, path string) error {
if shape == nil {
return fmt.Errorf("%s is nil", path)
}
switch value := shape.(type) {
case anyJSONShape:
case typedStringShape:
if value.MinLength != nil && *value.MinLength < 0 || value.MaxLength != nil && *value.MaxLength < 0 {
return fmt.Errorf("%s string lengths must be nonnegative", path)
}
if value.MinLength != nil && value.MaxLength != nil && *value.MinLength > *value.MaxLength {
return fmt.Errorf("%s minLength exceeds maxLength", path)
}
case typedBooleanShape:
case typedIntegerShape:
if value.Minimum != nil && value.Maximum != nil && *value.Minimum > *value.Maximum {
return fmt.Errorf("%s minimum exceeds maximum", path)
}
case typedNumberShape:
for _, number := range append(append([]float64{}, value.Enum...), pointerFloats(value.Minimum, value.Maximum)...) {
if math.IsNaN(number) || math.IsInf(number, 0) {
return fmt.Errorf("%s number constraints must be finite", path)
}
}
if value.Minimum != nil && value.Maximum != nil && *value.Minimum > *value.Maximum {
return fmt.Errorf("%s minimum exceeds maximum", path)
}View on GitHub (pinned to 7fd6ef3c07)
Solutions
- Locate the string shape at the reported path and check MinLength/MaxLength values.
- Set the offending bound to a nonnegative integer or remove the pointer to drop the constraint.
- If the value is computed, clamp or validate it before building the shape.
- Rerun the command registration; validateShape runs at compile/startup time so the fix is verified immediately.
Example fix
// before
shape := typedStringShape{MinLength: intPtr(-1)}
// after
shape := typedStringShape{MinLength: intPtr(0)} Defensive patterns
Strategy: validation
Validate before calling
func validStringLengths(s typedStringShape) bool {
nonneg := func(p *int) bool { return p == nil || *p >= 0 }
return nonneg(s.MinLength) && nonneg(s.MaxLength)
}
// if !validStringLengths(shape) { return errors.New("negative string length bound") } Type guard
func hasNegativeBound(p *int) bool { return p != nil && *p < 0 } Prevention
- Never use negative numbers as sentinels for 'unset'; use nil pointers.
- Clamp computed bounds to zero before building shapes.
- Centralize constraint construction in one helper that asserts nonnegativity.
- Run registration tests so validateShape failures appear in CI.
When it happens
Trigger: An explicit Output.Data.Shape (or DataField.Shape override) declares typedStringShape with MinLength or MaxLength pointing at a negative int; or a `schema:"minLength=-1"`-style tag value is lowered into the shape.
Common situations: Hand-writing shape constraints with a typo'd negative constant; computing a length bound from a variable that is negative (e.g. an unset size or a subtraction underflow); copy-pasting a constraint across fields and editing the sign.
Related errors
- %s minLength exceeds maxLength
- L1: inputSchema must not be nil
- L1: inputSchema.properties must not be nil
- L1: outputSchema must not be nil
- L1: _meta must not be nil
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/83c5a1fa74919cb4.
Report an issue: GitHub.