{"record":{"id":"9a69b4f424219a3d","repo":"kataras/iris","slug":"err-9a69b4","errorCode":null,"errorMessage":"err","messagePattern":"err","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"middleware/rewrite/rewrite.go","lineNumber":90,"sourceCode":"\tredirects []*redirectMatch\n\toptions   Options\n\n\tlogger          *golog.Logger\n\tdomainValidator func(string) bool\n}\n\n// Load decodes the \"filename\" options\n// and returns a new Rewrite Engine Router Wrapper.\n// It panics on errors.\n// Usage:\n// redirects := Load(\"redirects.yml\")\n// app.WrapRouter(redirects)\n// See `New` too.\nfunc Load(filename string) router.WrapperFunc {\n\topts := LoadOptions(filename)\n\tengine, err := New(opts)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn engine.Rewrite\n}\n\n// New returns a new Rewrite Engine based on \"opts\".\n// It reports any parser error.\n// See its `Handler` or `Rewrite` methods. Depending\n// on the needs, select one.\nfunc New(opts Options) (*Engine, error) {\n\tredirects := make([]*redirectMatch, 0, len(opts.RedirectMatch))\n\n\tfor _, line := range opts.RedirectMatch {\n\t\tr, err := parseRedirectMatchLine(line)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tredirects = append(redirects, r)\n\t}","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/middleware/rewrite/rewrite.go#L72-L108","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\napp.WrapRouter(rewrite.Load(\"redirects.yml\")) // panics on parse error\n// after\nopts := rewrite.LoadOptions{\"redirects.yml\"}\nengine, err := rewrite.New(opts)\nif err != nil {\n\tlog.Fatalf(\"invalid rewrite config: %v\", err)\n}\napp.WrapRouter(engine.Rewrite)","handlingStrategy":"validation","validationCode":"data, err := os.ReadFile(\"redirects.yml\")\nif err != nil { log.Fatalf(\"rewrite config missing: %v\", err) }\nvar check map[string]any\nif err := yaml.Unmarshal(data, &check); err != nil { log.Fatalf(\"invalid rewrite YAML: %v\", err) }","typeGuard":null,"tryCatchPattern":"defer func() {\n\tif r := recover(); r != nil {\n\t\tlog.Fatalf(\"rewrite.Load failed: %v\", r)\n\t}\n}()","preventionTips":["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."],"tags":["panic","config","yaml","routing","startup"],"backgroundTag":"config-parse-error","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}