Context
Very new to the language, so bear with me. I'm writing a super basic function to print out the command line arguments passed to the program. Here is the critical logic:
// already created allocator (std.heap.ArenaAllocator) and iterator (std.process.ArgIterator)
var idx: u16 = 0;
while (true) {
var arg = iterator.next(&allocator.allocator) catch |err| {
// ...
};
if (arg == null) {
print("End of arguments, exiting.", .{});
break;
}
print("Argument {d}: {s}", .{idx, arg});
idx += 1;
}
However, I'm getting an error message:
error: expected error union type, found '?std.process.NextError![:0]u8'
var arg = iterator.next(&allocator.allocator) catch |err| return err;
I think that the issue is tied to the fact that NextError returns an optional error union. I can't be sure though as I haven't found any documentation that covers this specific case.
Question
I got this code to work by removing the catch and pretending the error part of the return type doesn't exist. But the question is, what's the right way to catch that error?