JuliusBrussee/caveman · error · ErrRuleUnsupported

: (rule )

Error message

%w: %q (rule %q)

What it means

compileOrgRules rejects org-supplied rules whose Type is JSONPath or Header, because Payload only executes plain regex rules against the body. It wraps ErrRuleUnsupported and includes the offending type and rule name so the operator can locate the rule.

Solutions

  1. Replace the unsupported rule with an equivalent regex rule whose pattern targets the same content in the body.
  2. Drop or gate the JSONPath/Header rules before calling Payload, filtering with r.Type == redact.RuleTypeRegex.
  3. Handle errors.Is(err, redact.ErrRuleUnsupported) at call time and log which rule name/type was refused.

Example fix

// before
rules := []redact.Rule{{Name: "auth", Type: redact.RuleTypeHeader, Pattern: "Bearer"}}
out, _, err := redact.Payload(body, rules)
// after
rules := []redact.Rule{{Name: "auth", Type: redact.RuleTypeRegex, Pattern: "Bearer\\s+[A-Za-z0-9._-]+"}}
out, _, err := redact.Payload(body, rules)
Defensive patterns

Strategy: validation

Validate before calling

for i, r := range rules {
    if r.Type == redact.RuleTypeJSONPath || r.Type == redact.RuleTypeHeader {
        return fmt.Errorf("rule %d (%q): type %v unsupported by redact.Payload", i, r.Name, r.Type)
    }
}

Try / catch

out, report, err := redact.Payload(body, rules)
if errors.Is(err, redact.ErrRuleUnsupported) {
    // drop or translate the offending rule, then retry
}

Prevention

When it happens

Trigger: Passing a rules slice to redact.Payload containing a Rule with Type: RuleTypeJSONPath or Type: RuleTypeHeader. The error is returned before any matching occurs.

Common situations: Porting rule definitions authored for a different redaction engine that supported JSON-path or header-scoped matching; copying rule configs between tools with different capability sets.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/7d4a0040103d9a0f. Report an issue: GitHub.

Appendix: source

Thrown at shared/platform/redact/payload.go:573

	var sb strings.Builder
	for _, r := range sorted {
		sb.WriteString(r.Name)
		sb.WriteByte('\x1f')
		sb.WriteString(r.Type)
		sb.WriteByte('\x1f')
		sb.WriteString(r.Pattern)
		sb.WriteByte('\x1f')
		sb.WriteString(r.Replacement)
		sb.WriteByte('\x1e')

		switch r.Type {
		case RuleTypeBuiltin:
			// A reference to the unconditional floor. Nothing to run, and
			// nothing it could switch off.
			continue
		case RuleTypeRegex:
		case RuleTypeJSONPath, RuleTypeHeader:
			return nil, "", fmt.Errorf("%w: %q (rule %q)", ErrRuleUnsupported, r.Type, r.Name)
		default:
			return nil, "", fmt.Errorf("%w: %q (rule %q)", ErrRuleUnsupported, r.Type, r.Name)
		}

		if strings.TrimSpace(r.Name) == "" {
			return nil, "", fmt.Errorf("%w: empty name", ErrInvalidRule)
		}
		if r.Pattern == "" {
			return nil, "", fmt.Errorf("%w: rule %q has an empty pattern", ErrInvalidRule, r.Name)
		}
		re, err := regexp.Compile(r.Pattern)
		if err != nil {
			return nil, "", fmt.Errorf("%w: rule %q: %s", ErrInvalidRule, r.Name, err)
		}
		if re.MatchString("") {
			// Such a pattern matches at every position and would replace the
			// whole body with placeholders. Refuse it rather than destroy the
			// capture.

View on GitHub (pinned to 3ee70a1026)