kataras/iris · error

err

Error message

err

What it means

HTMLEngine.RootDir applies fs.Sub(s.fs, root) when the engine already holds a filesystem and a non-trivial different root is set. If the requested subdirectory does not exist in that filesystem, fs.Sub errors and the engine panics — an HTML template engine can't function without a valid template root.

Source

Thrown at view/html.go:98

				return template.HTML("")
			},
		},
		funcs: make(template.FuncMap),
		bufPool: &sync.Pool{New: func() any {
			return new(bytes.Buffer)
		}},
	}

	return s
}

// RootDir sets the directory to be used as a starting point
// to load templates from the provided file system.
func (s *HTMLEngine) RootDir(root string) *HTMLEngine {
	if s.fs != nil && root != "" && root != "/" && root != "." && root != s.rootDir {
		sub, err := fs.Sub(s.fs, root)
		if err != nil {
			panic(err)
		}
		s.fs = sub // here so the "middleware" can work.
	}

	s.rootDir = filepath.ToSlash(root)
	return s
}

// FS change templates DIR
func (s *HTMLEngine) FS(dirOrFS any) *HTMLEngine {
	s.fs = getFS(dirOrFS)
	return s
}

// Name returns the engine's name.
func (s *HTMLEngine) Name() string {
	return s.name
}

View on GitHub (pinned to 7bedaf55a0)

Solutions

  1. Check that the directory exists inside the FS before calling RootDir (fs.Stat(fsys, name)).
  2. Pass the root directly at construction: view.HTMLEngine(view.FS(fsys), "templates").
  3. Use forward slashes and paths relative to the FS root, never OS-specific paths.
  4. Avoid chaining RootDir with different values; set it once.

Example fix

// before
eng := view.HTMLEngine(view.FS(fsys))
eng.RootDir("views\\pages") // wrong separator/path -> panic
// after
eng := view.HTMLEngine(view.FS(fsys), "views/pages")
Defensive patterns

Strategy: validation

Validate before calling

const tplRoot = "templates" // forward slashes only
if _, err := fs.Stat(fsys, tplRoot); err != nil {
	log.Fatalf("html template root missing: %v", err)
}
engine.RootDir(tplRoot)

Try / catch

defer func() {
	if r := recover(); r != nil {
		log.Fatalf("HTMLEngine RootDir failed: %v", r)
	}
}()

Prevention

When it happens

Trigger: Calling html.RootDir("templates") after view.HTMLEngine(view.FS(fsys)) where "templates" is not a directory inside fsys, or calling RootDir twice with conflicting values.

Common situations: Embedded FS path prefix confusion (embed.FS paths start at the package dir), renaming the templates folder without updating RootDir, or OS path separators ("\\") instead of slashes.

Related errors


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