{"record":{"id":"83c5a1fa74919cb4","repo":"larksuite/cli","slug":"s-string-lengths-must-be-nonnegative","errorCode":null,"errorMessage":"%s string lengths must be nonnegative","messagePattern":"(.+?) string lengths must be nonnegative","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_compile_data.go","lineNumber":264,"sourceCode":"\t\t}\n\t\tfieldShape, err := shapeForType(field.Type, schema, input, active)\n\t\tif err != nil {\n\t\t\treturn typedObjectShape{}, fmt.Errorf(\"%s field %s (%s): %w\", path, field.Name, name, err)\n\t\t}\n\t\tshape.Fields = append(shape.Fields, typedValueField{Name: name, Description: description, Required: schema.required, Shape: fieldShape})\n\t}\n\treturn shape, nil\n}\n\nfunc validateShape(shape typedValueShape, path string) error {\n\tif shape == nil {\n\t\treturn fmt.Errorf(\"%s is nil\", path)\n\t}\n\tswitch value := shape.(type) {\n\tcase anyJSONShape:\n\tcase typedStringShape:\n\t\tif value.MinLength != nil && *value.MinLength < 0 || value.MaxLength != nil && *value.MaxLength < 0 {\n\t\t\treturn fmt.Errorf(\"%s string lengths must be nonnegative\", path)\n\t\t}\n\t\tif value.MinLength != nil && value.MaxLength != nil && *value.MinLength > *value.MaxLength {\n\t\t\treturn fmt.Errorf(\"%s minLength exceeds maxLength\", path)\n\t\t}\n\tcase typedBooleanShape:\n\tcase typedIntegerShape:\n\t\tif value.Minimum != nil && value.Maximum != nil && *value.Minimum > *value.Maximum {\n\t\t\treturn fmt.Errorf(\"%s minimum exceeds maximum\", path)\n\t\t}\n\tcase typedNumberShape:\n\t\tfor _, number := range append(append([]float64{}, value.Enum...), pointerFloats(value.Minimum, value.Maximum)...) {\n\t\t\tif math.IsNaN(number) || math.IsInf(number, 0) {\n\t\t\t\treturn fmt.Errorf(\"%s number constraints must be finite\", path)\n\t\t\t}\n\t\t}\n\t\tif value.Minimum != nil && value.Maximum != nil && *value.Minimum > *value.Maximum {\n\t\t\treturn fmt.Errorf(\"%s minimum exceeds maximum\", path)\n\t\t}","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_compile_data.go#L246-L282","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nshape := typedStringShape{MinLength: intPtr(-1)}\n// after\nshape := typedStringShape{MinLength: intPtr(0)}","handlingStrategy":"validation","validationCode":"func validStringLengths(s typedStringShape) bool {\n    nonneg := func(p *int) bool { return p == nil || *p >= 0 }\n    return nonneg(s.MinLength) && nonneg(s.MaxLength)\n}\n// if !validStringLengths(shape) { return errors.New(\"negative string length bound\") }","typeGuard":"func hasNegativeBound(p *int) bool { return p != nil && *p < 0 }","tryCatchPattern":null,"preventionTips":["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."],"tags":["go","schema","validation","string-constraints"],"backgroundTag":"invalid-schema-constraint","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}