thanos-io/thanos · error

fn (wrapped: rule file read error)

Error message

fn (wrapped: rule file read error)

What it means

Rules manager Update fails while unmarshalling a rule file: os.ReadFile succeeded but yaml.Unmarshal of the file's contents into configGroups failed, meaning the rule file is malformed YAML. The error is added to the MultiError tagged with the file name and Update continues with the remaining files.

Solutions

  1. Fix the YAML syntax in the reported rule file.
  2. Validate the file with yamllint or promtool before applying.
  3. Check the ConfigMap/secret rendering that produced the file.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pkg/rules/manager.go:351 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07). Data as JSON: /api/errors/dc2d5df01bba82fa. Report an issue: GitHub.

Appendix: source

Thrown at pkg/rules/manager.go:351

	}

	if err := os.RemoveAll(m.workDir); err != nil {
		return errors.Wrapf(err, "remove %s", m.workDir)
	}
	if err := os.MkdirAll(m.workDir, os.ModePerm); err != nil {
		return errors.Wrapf(err, "create %s", m.workDir)
	}

	for _, fn := range files {
		b, err := os.ReadFile(filepath.Clean(fn))
		if err != nil {
			errs.Add(err)
			continue
		}

		var rg configGroups
		if err := yaml.Unmarshal(b, &rg); err != nil {
			errs.Add(errors.Wrap(err, fn))
			continue
		}

		// NOTE: This is very ugly, but we need to write those yaml into tmp dir without the partial partial response field
		// which is not supported, to be able to reuse rules.Manager. The problem is that it uses yaml.UnmarshalStrict.
		groupsByStrategy := map[storepb.PartialResponseStrategy][]configRuleAdapter{}
		for _, rg := range rg.Groups {
			groupsByStrategy[*rg.PartialResponseStrategy] = append(groupsByStrategy[*rg.PartialResponseStrategy], rg)
		}
		for s, rg := range groupsByStrategy {
			b, err := yaml.Marshal(configGroups{Groups: rg})
			if err != nil {
				errs = append(errs, errors.Wrapf(err, "%s: failed to marshal rule groups", fn))
				continue
			}

			// Use full file name appending to work dir, so we can differentiate between different dirs and same filenames(!).
			// This will be also used as key for file group name.

View on GitHub (pinned to 35b8b99117)