{"record":{"id":"be51264a69b11ab6","repo":"kataras/iris","slug":"iris-rewrite-unexpected-file-extension","errorCode":null,"errorMessage":"iris: rewrite: unexpected file extension: ","messagePattern":"iris: rewrite: unexpected file extension: ","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"middleware/rewrite/rewrite.go","lineNumber":56,"sourceCode":"func 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}\n\n// Rewrite is a struct that represents a rewrite engine for Iris web framework.\n// It contains a slice of redirect rules, an options struct, a logger, and a domain validator function.\n// It provides methods to create, configure, and apply rewrite rules to HTTP requests and responses.\n//\n// Navigate through _examples/routing/rewrite for more.\ntype Engine struct {\n\tredirects []*redirectMatch\n\toptions   Options\n","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/middleware/rewrite/rewrite.go#L38-L74","documentation":"rewrite.LoadOptions dispatches on the filename extension and only understands .yaml, .yml, and .json. Any other (or missing) extension hits the default branch and panics with 'iris: rewrite: unexpected file extension: ' + filename. The decoder is chosen purely from the extension.","triggerScenarios":"Calling rewrite.Load(\"redirects.conf\"), rewrite.Load(\"redirects\") (no extension), or rewrite.Load(\"redirects.YAML\") — since ext is taken verbatim after the last dot, uppercase extensions are not matched.","commonSituations":"Config files named .yml.txt after an editor save; extensionless config paths; using .jsonc or .toml formats; Windows-authored files with uppercase extensions deployed to Linux.","solutions":["Rename the file to end with .yaml, .yml, or .json.","If content is JSON, ensure the extension is .json, not .conf/.txt.","Lowercase the extension if deploying to a case-sensitive filesystem."],"exampleFix":"// before\nrewrite.Load(\"redirects.conf\") // panic: unexpected file extension\n// after\nrewrite.Load(\"redirects.yml\")","handlingStrategy":"validation","validationCode":"ext := strings.ToLower(filepath.Ext(rulesPath))\nif ext != \".yaml\" && ext != \".yml\" && ext != \".json\" {\n    return fmt.Errorf(\"rewrite rules must be .yaml/.yml/.json, got %q\", ext)\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); strings.Contains(fmt.Sprint(r), \"unexpected file extension\") {\n        log.Fatalf(\"rewrite rules path bad extension: %v\", r)\n    }\n}()\nengine := rewrite.Load(rulesPath)","preventionTips":["Name config files with lowercase .yaml/.yml/.json extensions.","Strip editor-added suffixes (.txt) before deploying.","Validate the extension as part of config loading before calling rewrite.Load."],"tags":["go","panic","rewrite","file-extension","configuration"],"backgroundTag":"unsupported-file-extension","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}