{"record":{"id":"856cfbf0d07e3e73","repo":"kubernetes/kops","slug":"error-marshalling-host-data-w","errorCode":null,"errorMessage":"error marshalling host data: %w","messagePattern":"error marshalling host data: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/toolbox_enroll.go","lineNumber":148,"sourceCode":"\n\tsudo := options.SSHUser != \"root\"\n\n\tsshTarget, err := NewSSHHost(ctx, options.Host, options.SSHPort, options.SSHUser, sudo)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer sshTarget.Close()\n\n\thostData, err := buildHostData(ctx, sshTarget, options)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif options.BuildHost {\n\t\tklog.Infof(\"building host data for %+v\", hostData)\n\t\tb, err := yaml.Marshal(hostData)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error marshalling host data: %w\", err)\n\t\t}\n\t\tfmt.Fprintf(out, \"%s\\n\", string(b))\n\t\treturn nil\n\t}\n\n\tfullInstanceGroup, err := configBuilder.GetFullInstanceGroup(ctx)\n\tif err != nil {\n\t\treturn err\n\t}\n\tbootstrapData, err := configBuilder.GetBootstrapData(ctx)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif err := enrollHost(ctx, fullInstanceGroup, bootstrapData, restConfig, hostData, sshTarget); err != nil {\n\t\treturn err\n\t}\n","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/commands/toolbox_enroll.go#L130-L166","documentation":"With `--build-host` (dry-run mode), the command marshals the assembled BootstrapData/host configuration to YAML to print it. If yaml.Marshal fails on the hostData structure, the error is wrapped as \"error marshalling host data\".","triggerScenarios":"Running `kops toolbox enroll --build-host ...` where the populated hostData contains values that cannot be serialized to YAML/JSON-compatible form.","commonSituations":"Very rare; usually indicates a version mismatch between kops and the CRD schema (v1alpha2.Host) or corrupted bootstrap data (e.g. binary content in fields).","solutions":["Inspect the wrapped inner error to find the offending field","Upgrade/align kops and Cluster API provider CRD versions so Host schema matches","Re-run without --build-host to see whether the failure is specific to the dry-run path"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := RunToolboxEnroll(ctx, f, out, opts); err != nil {\n    var marshalErr interface{ Unwrap() error }\n    if strings.Contains(err.Error(), \"error marshalling host data\") {\n        log.Printf(\"host data serialization failed: %v\", err)\n    }\n    return err\n}","preventionTips":["Keep kops and CRD (v1alpha2.Host) versions in sync","Use --build-host dry-run on one host before batch enrollment","Avoid passing unusual characters/binary data through enroll flags"],"tags":["yaml","serialization","bare-metal"],"backgroundTag":"yaml-marshal-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}