crowdsecurity/crowdsec · error

unable to serialize overrides: %w

Error message

unable to serialize overrides: %w

What it means

InstallHub, when the test defines override statics, marshals a parser config containing them with yaml.Marshal to produce 00_overrides.yaml. If marshaling fails the error is wrapped as 'unable to serialize overrides: %w'. This is rare — yaml.Marshal only fails for unsupported types (e.g. channels, funcs) in the data.

Source

Thrown at pkg/hubtest/hubtest_item.go:221

	if err := t.installHubItems(t.Config.PostOverflows, t.installPostoverflow); err != nil {
		return err
	}

	if err := t.installHubItems(t.Config.AppsecRules, t.installAppsecRule); err != nil {
		return err
	}

	if len(t.Config.OverrideStatics) > 0 {
		cfg := parser.NodeConfig{
			Name:    "overrides",
			Filter:  "1==1",
			Statics: t.Config.OverrideStatics,
		}

		b, err := yaml.Marshal(cfg)
		if err != nil {
			return fmt.Errorf("unable to serialize overrides: %w", err)
		}

		tgtFilename := fmt.Sprintf("%s/parsers/s00-raw/00_overrides.yaml", t.RuntimePath)
		if err := os.WriteFile(tgtFilename, b, os.ModePerm); err != nil {
			return fmt.Errorf("unable to write overrides to '%s': %w", tgtFilename, err)
		}
	}

	// load installed hub
	hub, err := cwhub.NewHub(t.RuntimeHubConfig, nil)
	if err != nil {
		return err
	}

	if err := hub.Load(); err != nil {
		return err
	}

View on GitHub (pinned to 909b515798)

Solutions

  1. Inspect the wrapped error for the unsupported type and fix the OverrideStatics content in the test's config.yaml.
  2. Keep override statics as simple scalar/map values (strings, ints, bools) in the test config.
  3. If triggered programmatically, convert the offending field to a plain serializable value before calling Run.

Example fix

// before
statics: [{name: target_uri, value: !!binary aGk=, type: "unsupported"}]
// after
statics:
  - name: target_uri
    value: http://127.0.0.1:8080
    type: string
Defensive patterns

Strategy: try-catch

Validate before calling

for _, s := range item.Config.OverrideStatics {
    if _, err := yaml.Marshal(s); err != nil {
        log.Printf("non-marshalable override static: %+v", s)
    }
}

Try / catch

err := item.Run(ctx)
if err != nil && strings.Contains(err.Error(), "unable to serialize overrides") {
    log.Printf("fix OverrideStatics values in %s config: %v", item.Name, err)
}

Prevention

When it happens

Trigger: Calling HubTestItem.Run (via InstallHub) on a test whose Config.OverrideStatics contains values that the YAML marshaller cannot represent.

Common situations: Custom or programmatically built HubTestItem configs where override statics were populated with non-marshalable values instead of plain strings/maps; version upgrades introducing new field types into the parsed config struct.

Understand the failure class

Background: "JSON serialization failed", "not JSON serializable", "Failed to serialize": why JSON marshaling errors happen and how to fix them — this error's family across 46 libraries.

Related errors


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/8029bb9e72512d77. Report an issue: GitHub.