{"record":{"id":"e938bddf2358160a","repo":"larksuite/cli","slug":"parse-base-schema-for-field-overrides-w","errorCode":null,"errorMessage":"parse base schema for field overrides: %w","messagePattern":"parse base schema for field overrides: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/event/catalog/compile.go","lineNumber":238,"sourceCode":"\t\treturn nil, nil, nil\n\t}\n\n\tbase, err := renderSpec(spec)\n\tif err != nil {\n\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 {","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/event/catalog/compile.go#L220-L256","documentation":"resolveSchemaJSON in internal/event/catalog/compile.go fails when the base event schema JSON cannot be unmarshaled into a map prior to applying def.Schema.FieldOverrides. This step is only taken when field overrides exist; the wrap makes the JSON syntax/shape error diagnosable in a compile context.","triggerScenarios":"Compile() processes an event definition with non-empty Schema.FieldOverrides and json.Unmarshal(base, &parsed) fails because the base schema (possibly produced by WrapV2Envelope) is not valid JSON or is not a JSON object (e.g. array/string/number at top level).","commonSituations":"A custom or hand-edited event definition supplies a base schema that is invalid JSON; a generator emitted a non-object schema; binary/version mismatch where WrapV2Envelope output shape changed; metadata fetched from the server truncated or corrupted.","solutions":["Validate the base schema JSON parses (json.Valid or jq) before compiling; fix the invalid schema source","Ensure FieldOverrides target a base schema that is a JSON object; correct the definition's Schema field","Re-fetch/rebuild the canonical metadata instead of using a hand-modified schema","Check for a version mismatch between the code producing the base schema and the compiler"],"exampleFix":"// before\nbase := []byte(`{\"type\":\"object\"`) // malformed\n// after\nif !json.Valid(base) { return nil, nil, fmt.Errorf(\"invalid base schema\") }\nreturn resolveSchemaJSON(base, def)","handlingStrategy":"validation","validationCode":"if len(def.Schema.FieldOverrides) > 0 && !json.Valid(base) {\n    return fmt.Errorf(\"base schema for %s is not valid JSON\", def.Name)\n}","typeGuard":"func isSchemaParseError(err error) bool { return err != nil && strings.Contains(err.Error(), \"parse base schema\") }","tryCatchPattern":"schemaJSON, orphans, err := resolveSchemaJSON(base, def)\nif err != nil {\n    return fmt.Errorf(\"compile event %s: %w\", def.Name, err)\n}","preventionTips":["Validate schema JSON with json.Valid/jq before feeding custom definitions to Compile","Ensure base schemas are JSON objects, not arrays or scalars","Use generated/canonical metadata rather than hand-edited schemas","Test Compile over all definitions in CI to catch bad schema sources early"],"tags":["json","schema","compile","catalog"],"backgroundTag":"json-unmarshal-type-mismatch","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"}