{"record":{"id":"679c383ea70c11dd","repo":"kataras/iris","slug":"iris-rewrite","errorCode":null,"errorMessage":"iris: rewrite: ","messagePattern":"iris: rewrite: ","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"middleware/rewrite/rewrite.go","lineNumber":46,"sourceCode":"\n\t// Root domain requests redirect automatically to primary subdomain.\n\t// Example: \"www\" to redirect always to www.\n\t// Note that you SHOULD NOT create a www subdomain inside the Iris Application.\n\t// This field takes care of it for you, the root application instance\n\t// will be used to serve the requests.\n\tPrimarySubdomain string `json:\"primarySubdomain\" yaml:\"PrimarySubdomain\"`\n}\n\n// LoadOptions loads rewrite Options from a system file.\nfunc LoadOptions(filename string) (opts Options) {\n\text := \".yml\"\n\tif index := strings.LastIndexByte(filename, '.'); index > 1 && len(filename)-1 > index {\n\t\text = filename[index:]\n\t}\n\n\tf, err := os.Open(filename)\n\tif err != nil {\n\t\tpanic(\"iris: rewrite: \" + err.Error())\n\t}\n\tdefer f.Close()\n\n\tswitch ext {\n\tcase \".yaml\", \".yml\":\n\t\terr = yaml.NewDecoder(f).Decode(&opts)\n\tcase \".json\":\n\t\terr = json.NewDecoder(f).Decode(&opts)\n\tdefault:\n\t\tpanic(\"iris: rewrite: unexpected file extension: \" + filename)\n\t}\n\n\tif err != nil {\n\t\tpanic(\"iris: rewrite: decode: \" + err.Error())\n\t}\n\n\treturn\n}","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/middleware/rewrite/rewrite.go#L28-L64","documentation":"rewrite.LoadOptions opens the redirect rules file with os.Open; if the open fails it panics with 'iris: rewrite: ' + the OS error. This is startup fail-fast: the rewrite engine cannot work without its rules file. The filename extension determines the decoder (.yaml/.yml or .json).","triggerScenarios":"Calling rewrite.Load(\"redirects.yml\") where the path does not exist, the working directory differs from the expected one, or the process lacks read permission on the file.","commonSituations":"Relative path broken after deploying (binary run from a different cwd); file not copied into the Docker image; case-sensitive filename mismatch on Linux; permission denied after a chmod change.","solutions":["Check the file exists at the exact path (use an absolute path or embed it).","Fix file permissions (chmod/chown) so the running user can read it.","If the path is relative, resolve it relative to the executable or configure an explicit base directory."],"exampleFix":"// before\nengine := rewrite.Load(\"redirects.yaml\") // fails in container\n// after\n//go:embed redirects.yaml\nvar redirectsFS embed.FS\ndata, _ := redirectsFS.ReadFile(\"redirects.yaml\")\nos.WriteFile(\"/app/redirects.yaml\", data, 0644)\nengine := rewrite.Load(\"/app/redirects.yaml\")","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(rulesPath); err != nil {\n    return fmt.Errorf(\"rewrite rules file not readable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        log.Fatalf(\"rewrite load failed: %v\", r)\n    }\n}()\nengine := rewrite.Load(rulesPath)","preventionTips":["Embed the rules file with go:embed instead of relying on runtime paths.","Use absolute paths resolved from an env var with a sane default.","Add a startup smoke test that calls rewrite.Load on the packaged artifact."],"tags":["go","panic","rewrite","file-not-found","startup"],"backgroundTag":"file-not-found","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}