Fix panic when mixin not found with relative mixins_dir path

The loadMixinFromDir function used openDirAbsolute which requires an
absolute path, but ViewEngine passes a relative path for mixins_dir.
This caused a panic when a mixin call couldn't find the mixin in the
current template.

Fix: Check if mixins_dir is absolute and use the appropriate method:
- std.fs.openDirAbsolute() for absolute paths
- std.fs.cwd().openDir() for relative paths
This commit is contained in:
2026-01-19 19:01:50 +05:30
parent c73fb2ed03
commit 7d038df855

View File

@@ -867,7 +867,11 @@ pub const Runtime = struct {
} }
// Second try: iterate through all .pug files in mixins directory // Second try: iterate through all .pug files in mixins directory
var dir = std.fs.openDirAbsolute(self.mixins_dir, .{ .iterate = true }) catch return null; // Use cwd().openDir for relative paths, openDirAbsolute for absolute paths
var dir = if (std.fs.path.isAbsolute(self.mixins_dir))
std.fs.openDirAbsolute(self.mixins_dir, .{ .iterate = true }) catch return null
else
std.fs.cwd().openDir(self.mixins_dir, .{ .iterate = true }) catch return null;
defer dir.close(); defer dir.close();
var iter = dir.iterate(); var iter = dir.iterate();