{"record":{"id":"bd0080821206aca1","repo":"larksuite/cli","slug":"s-has-invalid-const-w","errorCode":null,"errorMessage":"%s has invalid const: %w","messagePattern":"(.+?) has invalid const: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_binder.go","lineNumber":403,"sourceCode":"\tswitch constraint := shape.(type) {\n\tcase anyJSONShape:\n\t\treturn nil\n\tcase typedOneOfShape:\n\t\tfor _, variant := range constraint.Variants {\n\t\t\tif err := validateJSONValueAgainstShape(value, variant, path); err == nil {\n\t\t\t\treturn nil\n\t\t\t}\n\t\t}\n\t\treturn fmt.Errorf(\"%s does not match any allowed shape\", path)\n\tcase typedNullShape:\n\t\tif value != nil {\n\t\t\treturn fmt.Errorf(\"%s must be null\", path)\n\t\t}\n\t\treturn nil\n\tcase typedConstShape:\n\t\texpectedJSON, err := json.Marshal(constraint.Value)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"%s has invalid const: %w\", path, err)\n\t\t}\n\t\texpected, err := decodeJSONValidationValue(expectedJSON)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"%s has invalid const: %w\", path, err)\n\t\t}\n\t\tif !reflect.DeepEqual(value, expected) {\n\t\t\treturn fmt.Errorf(\"%s must equal %v\", path, constraint.Value)\n\t\t}\n\t\treturn nil\n\tcase typedStringShape:\n\t\ttext, ok := value.(string)\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"%s must be a string\", path)\n\t\t}\n\t\tlength := len([]rune(text))\n\t\tif constraint.MinLength != nil && length < *constraint.MinLength {\n\t\t\treturn fmt.Errorf(\"%s must contain at least %d characters\", path, *constraint.MinLength)\n\t\t}","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_binder.go#L385-L421","documentation":"This wraps a json.Marshal failure while serializing a const-shape constraint's declared value. It means the shape definition itself contains a const value that cannot be JSON-encoded (e.g. a channel, func, or cyclic structure), not that the user's input is wrong. Thrown by validateJSONValueAgainstShape in the typedConstShape branch.","triggerScenarios":"A compiled shape declares constraint.Value as something json.Marshal cannot encode — func, channel, complex number, or a data structure containing them — so the const check fails before comparing input.","commonSituations":"A developer or generator builds shape constraints programmatically and puts a non-JSON-serializable Go value (e.g. a func or chan) into a const constraint.","solutions":["Replace the const value with a JSON-encodable equivalent (string, number, bool, map, slice).","Marshal the value to JSON at definition time and store the encoded form as the const.","Check for accidentally captured closures or channels in programmatically generated constraints."],"exampleFix":"// before\nconstraint.Value = func() bool { return true } // unmarshalable\n\n// after\nconstraint.Value = \"enabled\"","handlingStrategy":"fallback","validationCode":"if _, err := json.Marshal(constraint.Value); err != nil { return fmt.Errorf(\"invalid const definition: %w\", err) }","typeGuard":"func jsonEncodable(v any) bool { _, err := json.Marshal(v); return err == nil }","tryCatchPattern":"if err := binder.Set(\"mode\", input); err != nil {\n    if strings.Contains(err.Error(), \"has invalid const\") {\n        return fmt.Errorf(\"schema definition bug (const not JSON-encodable), not an input problem: %w\", err)\n    }\n    return err\n}","preventionTips":["Only use JSON-native values (string/number/bool/map/slice) in const constraints.","Unit-test shape definitions by marshaling every constraint.Value.","Ban func/chan fields in constraint-generating code."],"tags":["go","schema-validation","const","json-marshal"],"backgroundTag":"schema-validation-failed","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"}