kataras/iris · critical

iris: rewrite:

Error message

iris: rewrite: 

What it means

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).

Source

Thrown at middleware/rewrite/rewrite.go:46

	// Root domain requests redirect automatically to primary subdomain.
	// Example: "www" to redirect always to www.
	// Note that you SHOULD NOT create a www subdomain inside the Iris Application.
	// This field takes care of it for you, the root application instance
	// will be used to serve the requests.
	PrimarySubdomain string `json:"primarySubdomain" yaml:"PrimarySubdomain"`
}

// LoadOptions loads rewrite Options from a system file.
func LoadOptions(filename string) (opts Options) {
	ext := ".yml"
	if index := strings.LastIndexByte(filename, '.'); index > 1 && len(filename)-1 > index {
		ext = filename[index:]
	}

	f, err := os.Open(filename)
	if err != nil {
		panic("iris: rewrite: " + err.Error())
	}
	defer f.Close()

	switch ext {
	case ".yaml", ".yml":
		err = yaml.NewDecoder(f).Decode(&opts)
	case ".json":
		err = json.NewDecoder(f).Decode(&opts)
	default:
		panic("iris: rewrite: unexpected file extension: " + filename)
	}

	if err != nil {
		panic("iris: rewrite: decode: " + err.Error())
	}

	return
}

View on GitHub (pinned to 7bedaf55a0)

Solutions

  1. Check the file exists at the exact path (use an absolute path or embed it).
  2. Fix file permissions (chmod/chown) so the running user can read it.
  3. If the path is relative, resolve it relative to the executable or configure an explicit base directory.

Example fix

// before
engine := rewrite.Load("redirects.yaml") // fails in container
// after
//go:embed redirects.yaml
var redirectsFS embed.FS
data, _ := redirectsFS.ReadFile("redirects.yaml")
os.WriteFile("/app/redirects.yaml", data, 0644)
engine := rewrite.Load("/app/redirects.yaml")
Defensive patterns

Strategy: validation

Validate before calling

if _, err := os.Stat(rulesPath); err != nil {
    return fmt.Errorf("rewrite rules file not readable: %w", err)
}

Try / catch

defer func() {
    if r := recover(); r != nil {
        log.Fatalf("rewrite load failed: %v", r)
    }
}()
engine := rewrite.Load(rulesPath)

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30). Data as JSON: /api/errors/679c383ea70c11dd. Report an issue: GitHub.