larksuite/cli · error

serialize schema with field overrides: %w

Error message

serialize schema with field overrides: %w

What it means

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.

Source

Thrown at internal/event/catalog/compile.go:243

		return nil, nil, err
	}
	if base == nil {
		return nil, nil, nil
	}

	if isNative {
		base = schemas.WrapV2Envelope(base)
	}

	if len(def.Schema.FieldOverrides) > 0 {
		var parsed map[string]any
		if err := json.Unmarshal(base, &parsed); err != nil {
			return nil, nil, fmt.Errorf("parse base schema for field overrides: %w", err)
		}
		orphans := schemas.ApplyFieldOverrides(parsed, def.Schema.FieldOverrides)
		out, err := json.Marshal(parsed)
		if err != nil {
			return nil, nil, fmt.Errorf("serialize schema with field overrides: %w", err)
		}
		return out, orphans, nil
	}

	return base, nil, nil
}

// pickSpec returns the non-nil spec and whether it is native (V2-wrapped).
func pickSpec(s SchemaDef) (*SchemaSpec, bool) {
	if s.Native != nil {
		return s.Native, true
	}
	if s.Custom != nil {
		return s.Custom, false
	}
	return nil, false
}

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Inspect the wrapped Marshaler error message to identify the offending value/type
  2. Verify ApplyFieldOverrides (or the override source) only inserts JSON-encodable values into the map
  3. Ensure overrides are plain JSON-compatible values (string/number/bool/map/slice), not Go-native objects
  4. Reproduce with a minimal definition and dump the parsed map before Marshal

Example fix

// before
orphans := schemas.ApplyFieldOverrides(parsed, def.Schema.FieldOverrides) // injected non-JSON value
out, err := json.Marshal(parsed)
// after
parsed["myField"] = map[string]any{"type": "string"} // overrides must be JSON-compatible
out, err := json.Marshal(parsed)
Defensive patterns

Strategy: type-guard

Validate before calling

for k, v := range parsed {
    if !jsonMarshallable(v) { return fmt.Errorf("field %s not JSON-encodable", k) }
}

Type guard

func isSchemaMarshalError(err error) bool { return err != nil && strings.Contains(err.Error(), "serialize schema with field overrides") }

Try / catch

out, orphans, err := resolveSchemaJSON(base, def)
if err != nil {
    var me *json.MarshalerError
    if errors.As(err, &me) {
        log.Printf("non-encodable value of type %s", me.Type)
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/0831e8703c7822b1. Report an issue: GitHub.