openIterableDir returns entire error enum

I’m trying to include C source files in build.zig and I’ve been running into this error whilst trying to find all c files in a given directory. I’m using code from this blog post. I’m using version 0.11.0. Here’s the error output.

expected type 'void', found 'error{SystemResources,SymLinkLoop,ProcessFdQuotaExceeded,SystemFdQuotaExceeded,DeviceBusy,Unexpected,FileNotFound,NotDir,InvalidHandle,AccessDenied,NameTooLong,NoDevice,InvalidUtf8,BadPathName,NetworkNotFound}'
        var dir = try std.fs.cwd().openIterableDir(C_ROOT_DIR, .{ .access_sub_paths = true });
/Users/applejeewce/zig/mizumi/build.zig:6:29: note: function cannot return an error

I triple checked the directory, and even changed it up multiple times but I keep getting the same error. I’m on macOS.

I’d really appreciate any pointers that could help resolve this

Thank you

Edit: this may not apply to the version being presented here.

That post may be out of date? I’d just open the directory and make an iterator:

    var dir: std.fs.Dir = try std.fs.openDirAbsolute(self.source_directory, .{
        .access_sub_paths = false,
        .iterate = true,
        .no_follow = true,

    defer dir.close();

    var itr = dir.iterate();

    while (try |path| {
1 Like

The function that encloses the try cannot return errors.
If the return type is void change it to !void (that means error or void).


thank you! This helped. still very new to zig :sweat_smile:

Before we close this out - I’m searching the source here and not finding openIterableDir - @dimdin, do you know what source file that’s in?

here you go

Okay, so you’re looking at 0.11.0. That’s why I’m not finding it. Cool - thanks.


for context

1 Like

Thanks, @squeek502!