caddyserver/caddy · error

regexp pattern cannot be empty

Error message

regexp pattern cannot be empty

What it means

AddOperation on MultiRegexpFilter rejects an empty rawRegexp argument. It is the programmatic counterpart of the Validate() empty-pattern check: an empty pattern is treated as invalid input rather than a match-everything wildcard.

Source

Thrown at modules/logging/filters.go:1004

		// Ensure result doesn't exceed max length after each operation
		if len(result) > maxInputLength {
			result = result[:maxInputLength]
		}
	}
	return result
}

// AddOperation adds a single regexp operation to the filter with validation.
// This is used when merging multiple RegexpFilter instances.
func (f *MultiRegexpFilter) AddOperation(rawRegexp, value string) error {
	// Security checks
	if len(f.Operations) >= maxRegexpOperations {
		return fmt.Errorf("cannot add operation: maximum %d operations allowed", maxRegexpOperations)
	}

	if rawRegexp == "" {
		return fmt.Errorf("regexp pattern cannot be empty")
	}

	if len(rawRegexp) > maxPatternLength {
		return fmt.Errorf("regexp pattern too long: %d characters (maximum %d)", len(rawRegexp), maxPatternLength)
	}

	f.Operations = append(f.Operations, regexpFilterOperation{
		RawRegexp: rawRegexp,
		Value:     value,
	})
	return nil
}

// RenameFilter is a Caddy log field filter that
// renames the field's key with the indicated name.
type RenameFilter struct {
	Name string `json:"name,omitempty"`
}

View on GitHub (pinned to 50e54ee279)

Solutions

  1. Skip empty patterns in the merge loop before calling AddOperation
  2. Fix the source of the empty value (missing key in JSON/Caddyfile)
  3. Use ".*" if a catch-all was intended

Example fix

// before
mf.AddOperation(cfg.Search, cfg.Replace) // cfg.Search == ""

// after
if cfg.Search != "" {
    if err := mf.AddOperation(cfg.Search, cfg.Replace); err != nil {
        return err
    }
}
Defensive patterns

Strategy: validation

Validate before calling

if rawRegexp == "" { return nil /* skip empty */ }
if err := mf.AddOperation(rawRegexp, value); err != nil { return err }

Prevention

When it happens

Trigger: Calling mf.AddOperation("", value) (or with a variable that resolved to empty, e.g. an unset config key) when merging RegexpFilter instances.

Common situations: Merge loops that pass filter structs with zero-value Search fields; config-driven code where the search expression failed to populate; empty string slipping through after placeholder substitution.

Related errors


AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15). Data as JSON: /api/errors/e8516c89e723023d. Report an issue: GitHub.