AdguardTeam/AdGuardHome · error

generating new config: %w

Error message

generating new config: %w

What it means

Migrate successfully transformed the config in memory but failed to re-encode it back to YAML. The yaml Encoder error is wrapped with "generating new config".

Source

Thrown at internal/configmigrate/migrator.go:82

	if err = validateVersion(current, target); err != nil {
		// Don't wrap the error, since it's informative enough as is.
		return body, false, err
	} else if current == target {
		return body, false, nil
	}

	if err = m.upgradeConfigSchema(ctx, current, target, diskConf); err != nil {
		// Don't wrap the error, since it's informative enough as is.
		return body, false, err
	}

	buf := bytes.NewBuffer(newBody)
	enc := yaml.NewEncoder(buf)
	enc.SetIndent(2)

	if err = enc.Encode(diskConf); err != nil {
		return body, false, fmt.Errorf("generating new config: %w", err)
	}

	return buf.Bytes(), true, nil
}

// validateVersion validates the current and desired schema versions.
func validateVersion(current, target uint) (err error) {
	switch {
	case current > target:
		return fmt.Errorf("unknown current schema version %d", current)
	case target > LastSchemaVersion:
		return fmt.Errorf("unknown target schema version %d", target)
	case target < current:
		return fmt.Errorf("target schema version %d lower than current %d", target, current)
	default:
		return nil
	}
}

View on GitHub (pinned to b41aefbe51)

Solutions

  1. Inspect the migrated config map for non-serializable values (float NaN, unusual key types) added by migration logic
  2. Fix the offending migration step to write plain strings/ints/maps
  3. On encoder failure the original body is returned, so the old config is still usable — fix and retry Migrate
Defensive patterns

Strategy: try-catch

Try / catch

newBody, upgraded, err := configmigrate.Migrate(ctx, body, target)
if err != nil && strings.Contains(err.Error(), "generating new config") { /* keep original body (returned on failure) and log; migration is retryable */ }

Prevention

When it happens

Trigger: Calling Migrate where diskConf, after migrations, contains values the YAML encoder cannot serialize (e.g. NaN/Inf floats, unsupported map key types, cyclic structures injected by a custom migration).

Common situations: A buggy custom migration step leaves invalid value types in the map; extremely rare in practice since migrations only manipulate plain maps, slices, and scalars.

Related errors


AI-assisted analysis of AdguardTeam/AdGuardHome@b41aefbe51 (2026-08-27). Data as JSON: /api/errors/afa360ec32f7e4af. Report an issue: GitHub.