{"record":{"id":"afa360ec32f7e4af","repo":"AdguardTeam/AdGuardHome","slug":"generating-new-config-w","errorCode":null,"errorMessage":"generating new config: %w","messagePattern":"generating new config: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/configmigrate/migrator.go","lineNumber":82,"sourceCode":"\n\tif err = validateVersion(current, target); err != nil {\n\t\t// Don't wrap the error, since it's informative enough as is.\n\t\treturn body, false, err\n\t} else if current == target {\n\t\treturn body, false, nil\n\t}\n\n\tif err = m.upgradeConfigSchema(ctx, current, target, diskConf); err != nil {\n\t\t// Don't wrap the error, since it's informative enough as is.\n\t\treturn body, false, err\n\t}\n\n\tbuf := bytes.NewBuffer(newBody)\n\tenc := yaml.NewEncoder(buf)\n\tenc.SetIndent(2)\n\n\tif err = enc.Encode(diskConf); err != nil {\n\t\treturn body, false, fmt.Errorf(\"generating new config: %w\", err)\n\t}\n\n\treturn buf.Bytes(), true, nil\n}\n\n// validateVersion validates the current and desired schema versions.\nfunc validateVersion(current, target uint) (err error) {\n\tswitch {\n\tcase current > target:\n\t\treturn fmt.Errorf(\"unknown current schema version %d\", current)\n\tcase target > LastSchemaVersion:\n\t\treturn fmt.Errorf(\"unknown target schema version %d\", target)\n\tcase target < current:\n\t\treturn fmt.Errorf(\"target schema version %d lower than current %d\", target, current)\n\tdefault:\n\t\treturn nil\n\t}\n}","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/AdguardTeam/AdGuardHome/blob/b41aefbe51c8dde65e2c50f093996afa0502edf9/internal/configmigrate/migrator.go#L64-L100","documentation":"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\".","triggerScenarios":"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).","commonSituations":"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.","solutions":["Inspect the migrated config map for non-serializable values (float NaN, unusual key types) added by migration logic","Fix the offending migration step to write plain strings/ints/maps","On encoder failure the original body is returned, so the old config is still usable — fix and retry Migrate"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"newBody, upgraded, err := configmigrate.Migrate(ctx, body, target)\nif err != nil && strings.Contains(err.Error(), \"generating new config\") { /* keep original body (returned on failure) and log; migration is retryable */ }","preventionTips":["On failure Migrate returns the original body — write that back to disk to keep a valid config","Keep backups of the config before migrations"],"tags":["config","yaml","migration","serialization"],"backgroundTag":"yaml-serialization-error","analyzedSha":"b41aefbe51c8dde65e2c50f093996afa0502edf9","analyzedAt":"2026-08-27T04:57:55.097Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}