Repository: prometheus/prometheus
File: model/rulefmt/rulefmt.go (Go)

Code before:
				node: &r.Record,
			})
		}
		if r.For != 0 {
			nodes = append(nodes, WrappedError{
				err:  errors.New("invalid field 'for' in recording rule"),
				node: &r.Record,
			})
		}
		if r.KeepFiringFor != 0 {
			nodes = append(nodes, WrappedError{
				err:  errors.New("invalid field 'keep_firing_for' in recording rule"),
				node: &r.Record,
			})
		}
		if !model.IsValidMetricName(model.LabelValue(r.Record.Value)) {
			nodes = append(nodes, WrappedError{
				err:  fmt.Errorf("invalid recording rule name: %s", r.Record.Value),
				node: &r.Record,
			})
		}
		// While record is a valid UTF-8 it's common mistake to put PromQL expression in the record name.
		// Disallow "{}" chars.
		if strings.Contains(r.Record.Value, "{") || strings.Contains(r.Record.Value, "}") {
			nodes = append(nodes, WrappedError{
				err:  fmt.Errorf("potential issue in the recording rule name; should it be in expr?: %s", r.Record.Value),
				node: &r.Record,
			})
		}
	}

	for k, v := range r.Labels {
		if !model.LabelName(k).IsValid() || k == model.MetricNameLabel {
			nodes = append(nodes, WrappedError{
				err: fmt.Errorf("invalid label name: %s", k),
			})
		}

		if !model.LabelValue(v).IsValid() {
			nodes = append(nodes, WrappedError{
				err: fmt.Errorf("invalid label value: %s", v),
			})
		}
	}

	for k := range r.Annotations {
		if !model.LabelName(k).IsValid() {
			nodes = append(nodes, WrappedError{
				err: fmt.Errorf("invalid annotation name: %s", k),
			})
		}

Review comment (suggestion):
Let's make it explicit in the error what the "issue" is, otherwise users might not understand why it's being triggered

```suggestion
				err:  fmt.Errorf("braces present in the recording rule name; should it be in expr?: %s", r.Record.Value),
```

Code after:
				node: &r.Record,
			})
		}
		if r.For != 0 {
			nodes = append(nodes, WrappedError{
				err:  errors.New("invalid field 'for' in recording rule"),
				node: &r.Record,
			})
		}
		if r.KeepFiringFor != 0 {
			nodes = append(nodes, WrappedError{
				err:  errors.New("invalid field 'keep_firing_for' in recording rule"),
				node: &r.Record,
			})
		}
		if !model.IsValidMetricName(model.LabelValue(r.Record.Value)) {
			nodes = append(nodes, WrappedError{
				err:  fmt.Errorf("invalid recording rule name: %s", r.Record.Value),
				node: &r.Record,
			})
		}
		// While record is a valid UTF-8 it's common mistake to put PromQL expression in the record name.
		// Disallow "{}" chars.
		if strings.Contains(r.Record.Value, "{") || strings.Contains(r.Record.Value, "}") {
			nodes = append(nodes, WrappedError{
				err:  fmt.Errorf("braces present in the recording rule name; should it be in expr?: %s", r.Record.Value),
				node: &r.Record,
			})
		}
	}

	for k, v := range r.Labels {
		if !model.LabelName(k).IsValid() || k == model.MetricNameLabel {
			nodes = append(nodes, WrappedError{
				err: fmt.Errorf("invalid label name: %s", k),
			})
		}

		if !model.LabelValue(v).IsValid() {
			nodes = append(nodes, WrappedError{
				err: fmt.Errorf("invalid label value: %s", v),
			})
		}
	}

	for k := range r.Annotations {
		if !model.LabelName(k).IsValid() {
			nodes = append(nodes, WrappedError{
				err: fmt.Errorf("invalid annotation name: %s", k),
			})
		}