std.Io.Dir.walk requires iterate = true, but this is never stated

I have this simple test case. I noticed my program giving me an Unexpected error when trying to call .next() on a walker, so decided ot investigate. For some reason I can’t get my test program to do this, but it does panic. From my reading of the docs, it’s specified that iterate = true is needed for iterate, but not walk. it makes sense, buty I didn’t think of it.

const std = @import("std");

pub fn main(init: std.process.Init) !void {
    const allocator = init.gpa;
    const io = init.io;
    std.debug.print("Testing with iterate = true…\n", .{});
    var dir1 = try std.Io.Dir.cwd().openDir(io, ".", .{ .iterate = true });
    defer dir1.close(io);
    var w1 = try dir1.walk(allocator);
    defer w1.deinit();
    _ = try w1.next(io);
    std.debug.print("Success. Testing with iterate = false…\n", .{});
    var dir2 = try std.Io.Dir.cwd().openDir(io, ".", .{ .iterate = false });
    defer dir2.close(io);
    var w2 = try dir2.walk(allocator);
    defer w2.deinit();
    _ = try w2.next(io);
    std.debug.print("No errors.\n", .{});
}

In the docs of std.Io.Dir.walk:

dir must have been opened with OpenOptions.iterate set to true.

2 Likes

No idea how I missed that despite reading it 4 times…derp. Sorry everyone!

1 Like

@Quin Switch to markdown mode with the first button in the toolbar or ctrl-M, to avoid weird auto formatting and smart (dumb) quotes. For more info read this I cannot create multi-line code blocks anymore