{"record":{"id":"3c0cb8cf023c780e","repo":"larksuite/cli","slug":"s-const-is-not-json-encodable-w","errorCode":null,"errorMessage":"%s const is not JSON-encodable: %w","messagePattern":"(.+?) const is not JSON-encodable: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_compile_data.go","lineNumber":286,"sourceCode":"\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}\n\tcase typedNullShape:\n\tcase typedConstShape:\n\t\tif _, err := json.Marshal(value.Value); err != nil {\n\t\t\treturn fmt.Errorf(\"%s const is not JSON-encodable: %w\", path, err)\n\t\t}\n\tcase typedArrayShape:\n\t\tif value.Items == nil {\n\t\t\treturn fmt.Errorf(\"%s.Items is required\", path)\n\t\t}\n\t\tif value.MinItems != nil && *value.MinItems < 0 || value.MaxItems != nil && *value.MaxItems < 0 {\n\t\t\treturn fmt.Errorf(\"%s item lengths must be nonnegative\", path)\n\t\t}\n\t\tif value.MinItems != nil && value.MaxItems != nil && *value.MinItems > *value.MaxItems {\n\t\t\treturn fmt.Errorf(\"%s minItems exceeds maxItems\", path)\n\t\t}\n\t\treturn validateShape(value.Items, path+\".Items\")\n\tcase typedObjectShape:\n\t\tseen := make(map[string]struct{})\n\t\tfor i := range value.Fields {\n\t\t\tfield := &value.Fields[i]\n\t\t\tif field.Name == \"\" {\n\t\t\t\treturn fmt.Errorf(\"%s.Fields[%d].Name is required\", path, i)","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_compile_data.go#L268-L304","documentation":"validateShape rejects a typedConstShape whose Value cannot be marshaled with encoding/json. Const values are emitted verbatim into the generated schema, so they must be JSON-encodable; the wrapped json.Marshal error and the shape path are included in the message.","triggerScenarios":"An explicit Output.Data.Shape or DataField.Shape override sets typedConstShape.Value to a channel, func, complex number, or a type whose MarshalJSON returns an error; json.Marshal inside validateShape then fails and the cause is wrapped.","commonSituations":"Using a custom type with a MarshalJSON implementation that errors for the given value (e.g. an invalid time or an enum without a mapping); accidentally embedding a non-serializable Go value like a func or channel in the const.","solutions":["Read the wrapped json.Marshal cause to see which type failed to encode.","Replace the const Value with a JSON-native Go value (string, number, bool, nil, or composed slices/maps).","If a custom MarshalJSON is involved, fix it to handle the value or marshal the underlying concrete value instead.","Pre-marshal the value in a test to catch this before registration."],"exampleFix":"// before\nshape := typedConstShape{Value: make(chan int)} // not JSON-encodable\n// after\nshape := typedConstShape{Value: 42}","handlingStrategy":"validation","validationCode":"func jsonEncodableConst(v any) error {\n    if _, err := json.Marshal(v); err != nil {\n        return fmt.Errorf(\"const value not JSON-encodable: %w\", err)\n    }\n    return nil\n}\n// if err := jsonEncodableConst(shape.Value); err != nil { return err }","typeGuard":"func isJSONNative(v any) bool {\n    switch v.(type) {\n    case nil, string, bool, float64, int, int64, json.RawMessage:\n        return true\n    }\n    rv := reflect.ValueOf(v)\n    switch rv.Kind() {\n    case reflect.Slice, reflect.Array, reflect.Map, reflect.Struct, reflect.Pointer:\n        return true // still verify via json.Marshal for custom encoders\n    default:\n        return false // chan, func, complex, etc.\n    }\n}","tryCatchPattern":null,"preventionTips":["Restrict const values to JSON-native Go types (string, number, bool, nil, slices/maps/structs).","Never embed channels, funcs, or complex numbers in const shapes.","If a custom MarshalJSON backs the value, test that it succeeds for the concrete value used."],"tags":["go","json","schema","validation"],"backgroundTag":"json-marshal-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"}