{"record":{"id":"9bc4d6705335b269","repo":"thanos-io/thanos","slug":"s-failed-to-marshal-rule-groups","errorCode":null,"errorMessage":"%s: failed to marshal rule groups","messagePattern":"(.+?): failed to marshal rule groups","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/rules/manager.go","lineNumber":364,"sourceCode":"\t\t\tcontinue\n\t\t}\n\n\t\tvar rg configGroups\n\t\tif err := yaml.Unmarshal(b, &rg); err != nil {\n\t\t\terrs.Add(errors.Wrap(err, fn))\n\t\t\tcontinue\n\t\t}\n\n\t\t// NOTE: This is very ugly, but we need to write those yaml into tmp dir without the partial partial response field\n\t\t// which is not supported, to be able to reuse rules.Manager. The problem is that it uses yaml.UnmarshalStrict.\n\t\tgroupsByStrategy := map[storepb.PartialResponseStrategy][]configRuleAdapter{}\n\t\tfor _, rg := range rg.Groups {\n\t\t\tgroupsByStrategy[*rg.PartialResponseStrategy] = append(groupsByStrategy[*rg.PartialResponseStrategy], rg)\n\t\t}\n\t\tfor s, rg := range groupsByStrategy {\n\t\t\tb, err := yaml.Marshal(configGroups{Groups: rg})\n\t\t\tif err != nil {\n\t\t\t\terrs = append(errs, errors.Wrapf(err, \"%s: failed to marshal rule groups\", fn))\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\t// Use full file name appending to work dir, so we can differentiate between different dirs and same filenames(!).\n\t\t\t// This will be also used as key for file group name.\n\t\t\tnewFn := filepath.Join(m.workDir, s.String(), fn)\n\t\t\tif err := os.MkdirAll(filepath.Dir(newFn), os.ModePerm); err != nil {\n\t\t\t\terrs.Add(errors.Wrapf(err, \"create %s\", filepath.Dir(newFn)))\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif err := os.WriteFile(newFn, b, os.ModePerm); err != nil {\n\t\t\t\terrs.Add(errors.Wrapf(err, \"write file %v\", newFn))\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tfilesByStrategy[s] = append(filesByStrategy[s], newFn)\n\t\t\truleFiles[newFn] = fn\n\t\t}\n\t}","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/rules/manager.go#L346-L382","documentation":"Raised in Manager.Update while re-serializing each parsed rule group file back to YAML, grouped by partial-response strategy, into the manager's workDir. It fires when yaml.Marshal of a strategy's configGroups fails, which is unexpected since the groups were just unmarshaled successfully; it indicates a serialization defect or unsupported field content, and that strategy's rule file is skipped.","triggerScenarios":"Thrown at pkg/rules/manager.go:364 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the rule group content for fields that fail YAML marshaling","Update Thanos/Prometheus rule config structs if a newly supported field is not marshalable","Inspect the wrapped yaml.Marshal error to identify the offending field"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}