kataras/iris · critical
err
Error message
err
What it means
middleware/rewrite.Load loads a rewrite engine from a YAML file and panics on any parser/option error, because it returns only a router wrapper and has no error return. Any invalid rewrite syntax, unreadable file, or schema violation in the YAML surfaces as this generic wrapped error at startup. It is a fail-fast design: the app cannot serve traffic without a valid rewrite table.
Source
Thrown at middleware/rewrite/rewrite.go:90
redirects []*redirectMatch
options Options
logger *golog.Logger
domainValidator func(string) bool
}
// Load decodes the "filename" options
// and returns a new Rewrite Engine Router Wrapper.
// It panics on errors.
// Usage:
// redirects := Load("redirects.yml")
// app.WrapRouter(redirects)
// See `New` too.
func Load(filename string) router.WrapperFunc {
opts := LoadOptions(filename)
engine, err := New(opts)
if err != nil {
panic(err)
}
return engine.Rewrite
}
// New returns a new Rewrite Engine based on "opts".
// It reports any parser error.
// See its `Handler` or `Rewrite` methods. Depending
// on the needs, select one.
func New(opts Options) (*Engine, error) {
redirects := make([]*redirectMatch, 0, len(opts.RedirectMatch))
for _, line := range opts.RedirectMatch {
r, err := parseRedirectMatchLine(line)
if err != nil {
return nil, err
}
redirects = append(redirects, r)
}View on GitHub (pinned to 7bedaf55a0)
Solutions
- Check the panic text for the parser message and fix the offending line in the rewrite YAML file.
- Verify the file path passed to Load is correct and the file exists/is readable at runtime.
- Prefer building with rewrite.New(rewrite.LoadOptions{...}) which returns an error you can handle instead of Load's panic.
- Add a config-load step at boot that validates the YAML (yaml.Unmarshal into the expected struct) before calling Load.
Example fix
// before
app.WrapRouter(rewrite.Load("redirects.yml")) // panics on parse error
// after
opts := rewrite.LoadOptions{"redirects.yml"}
engine, err := rewrite.New(opts)
if err != nil {
log.Fatalf("invalid rewrite config: %v", err)
}
app.WrapRouter(engine.Rewrite) Defensive patterns
Strategy: validation
Validate before calling
data, err := os.ReadFile("redirects.yml")
if err != nil { log.Fatalf("rewrite config missing: %v", err) }
var check map[string]any
if err := yaml.Unmarshal(data, &check); err != nil { log.Fatalf("invalid rewrite YAML: %v", err) } Try / catch
defer func() {
if r := recover(); r != nil {
log.Fatalf("rewrite.Load failed: %v", r)
}
}() Prevention
- Validate the rewrite YAML in CI before deploying.
- Use rewrite.New instead of rewrite.Load to get a returnable error.
- Keep the redirects file in version control and lint it.
When it happens
Trigger: Calling rewrite.Load("redirects.yml") with a file that does not exist, is not valid YAML, or whose keys/values do not match the expected rewrite schema (e.g. a source pattern with invalid syntax).
Common situations: Typos in the redirects file path, manually edited redirect rules with bad regex/anchors, CI deploying an empty or corrupted config file, or a schema change after upgrading iris.
Related errors
- panic(err)
- err
- iris: switch: hosts: invalid target type: %T
- panic(err)
- default configuration file '" + filename + "' does not exist
AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30).
Data as JSON: /api/errors/9a69b4f424219a3d.
Report an issue: GitHub.