{"record":{"id":"53ad9ebd01fcdb3b","repo":"kataras/iris","slug":"iris-rewrite-decode","errorCode":null,"errorMessage":"iris: rewrite: decode: ","messagePattern":"iris: rewrite: decode: ","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"middleware/rewrite/rewrite.go","lineNumber":60,"sourceCode":"\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\n\tlogger          *golog.Logger\n\tdomainValidator func(string) bool\n}\n","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/middleware/rewrite/rewrite.go#L42-L78","documentation":"After opening the rules file, rewrite.LoadOptions decodes it with the yaml or json decoder chosen by extension; a decode error is re-panicked prefixed with 'iris: rewrite: decode: '. The file was found and the extension was valid, but its contents do not parse as the corresponding format or do not fit the Options structure.","triggerScenarios":"Loading a .yml file with YAML syntax errors (bad indentation, tabs), or a .json file with trailing commas/comments, or content whose types don't match rewrite.Options fields (e.g. a string where a list of RedirectMatch objects is expected).","commonSituations":"Hand-edited YAML using tabs instead of spaces; JSON file exported with comments; redirect rules defined in a shape the Options struct doesn't recognize; merge artifacts (<<<<<<< markers) left in the file.","solutions":["Validate the file with a YAML/JSON parser and fix the reported syntax error (line/column is in the panic message).","Check that the document structure matches rewrite.Options (primary ROOT redirection plus list of redirect match rules).","Test parsing in a unit test with yaml.Unmarshal/json.Unmarshal on the same file so failures surface with full error detail."],"exampleFix":"// before (redirects.yml)\nredirects:\n\t- /old /new   # tab indentation -> decode error\n// after (redirects.yml)\nredirects:\n  - /old /new","handlingStrategy":"validation","validationCode":"data, err := os.ReadFile(rulesPath)\nif err != nil { return err }\nswitch strings.ToLower(filepath.Ext(rulesPath)) {\ncase \".yaml\", \".yml\":\n    var v any\n    if err := yaml.Unmarshal(data, &v); err != nil {\n        return fmt.Errorf(\"invalid rewrite yaml: %w\", err)\n    }\ncase \".json\":\n    if !json.Valid(data) {\n        return errors.New(\"invalid rewrite json\")\n    }\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        log.Fatalf(\"rewrite rules decode failed: %v\", r)\n    }\n}()\nengine := rewrite.Load(rulesPath)","preventionTips":["Run a YAML/JSON linter on rewrite rules files in CI.","Use spaces, never tabs, in YAML rules files.","Keep the document structure aligned with rewrite.Options and test-parse it in a unit test."],"tags":["go","panic","rewrite","yaml","json","parse-error","configuration"],"backgroundTag":"schema-validation-failed","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}