{"record":{"id":"0831e8703c7822b1","repo":"larksuite/cli","slug":"serialize-schema-with-field-overrides-w","errorCode":null,"errorMessage":"serialize schema with field overrides: %w","messagePattern":"serialize schema with field overrides: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/event/catalog/compile.go","lineNumber":243,"sourceCode":"\t\treturn nil, nil, err\n\t}\n\tif base == nil {\n\t\treturn nil, nil, nil\n\t}\n\n\tif isNative {\n\t\tbase = schemas.WrapV2Envelope(base)\n\t}\n\n\tif len(def.Schema.FieldOverrides) > 0 {\n\t\tvar parsed map[string]any\n\t\tif err := json.Unmarshal(base, &parsed); err != nil {\n\t\t\treturn nil, nil, fmt.Errorf(\"parse base schema for field overrides: %w\", err)\n\t\t}\n\t\torphans := schemas.ApplyFieldOverrides(parsed, def.Schema.FieldOverrides)\n\t\tout, err := json.Marshal(parsed)\n\t\tif err != nil {\n\t\t\treturn nil, nil, fmt.Errorf(\"serialize schema with field overrides: %w\", err)\n\t\t}\n\t\treturn out, orphans, nil\n\t}\n\n\treturn base, nil, nil\n}\n\n// pickSpec returns the non-nil spec and whether it is native (V2-wrapped).\nfunc pickSpec(s SchemaDef) (*SchemaSpec, bool) {\n\tif s.Native != nil {\n\t\treturn s.Native, true\n\t}\n\tif s.Custom != nil {\n\t\treturn s.Custom, false\n\t}\n\treturn nil, false\n}\n","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/event/catalog/compile.go#L225-L261","documentation":"resolveSchemaJSON in internal/event/catalog/compile.go fails when the modified schema map (after ApplyFieldOverrides) cannot be re-marshaled back to JSON. Since the input came from a successful json.Unmarshal into map[string]any, this failure is rare and indicates an underlying encoding anomaly or resource issue rather than bad user input.","triggerScenarios":"Compile() processes a definition with field overrides; after ApplyFieldOverrides mutates the parsed map, json.Marshal(parsed) returns an error — practically only if the map came to hold an unsupported value type (not possible from plain JSON unmarshal unless overrides inject one) or the JSON encoder hits an internal failure.","commonSituations":"A custom ApplyFieldOverrides implementation or override value source injects values that are not JSON-encodable (e.g. channel, func) — usually only in tests or patched builds; extremely large schemas exhausting memory in constrained environments.","solutions":["Inspect the wrapped Marshaler error message to identify the offending value/type","Verify ApplyFieldOverrides (or the override source) only inserts JSON-encodable values into the map","Ensure overrides are plain JSON-compatible values (string/number/bool/map/slice), not Go-native objects","Reproduce with a minimal definition and dump the parsed map before Marshal"],"exampleFix":"// before\norphans := schemas.ApplyFieldOverrides(parsed, def.Schema.FieldOverrides) // injected non-JSON value\nout, err := json.Marshal(parsed)\n// after\nparsed[\"myField\"] = map[string]any{\"type\": \"string\"} // overrides must be JSON-compatible\nout, err := json.Marshal(parsed)","handlingStrategy":"type-guard","validationCode":"for k, v := range parsed {\n    if !jsonMarshallable(v) { return fmt.Errorf(\"field %s not JSON-encodable\", k) }\n}","typeGuard":"func isSchemaMarshalError(err error) bool { return err != nil && strings.Contains(err.Error(), \"serialize schema with field overrides\") }","tryCatchPattern":"out, orphans, err := resolveSchemaJSON(base, def)\nif err != nil {\n    var me *json.MarshalerError\n    if errors.As(err, &me) {\n        log.Printf(\"non-encodable value of type %s\", me.Type)\n    }\n    return err\n}","preventionTips":["Keep override values strictly JSON-compatible (maps, slices, scalars)","Do not inject Go-native objects via custom override logic","Dump the parsed map before Marshal when debugging overrides","Prefer re-marshaling through the standard library only, no custom encoders"],"tags":["json","schema","marshal","catalog"],"backgroundTag":"json-marshal-unsupported-type","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"}