Thread behavior when the callback returns an error

Consider the following code:

fn opps()  anyerror!void {
    return error.SubmissionQueueFull;
}

pub fn main() anyerror!void {
    var t = try std.Thread.spawn(.{}, opps, .{});
    t.join();
}

As you can see, the thread function will return an error. From my observations of Zig code, it seems that it is valid to write this code. However, there is no way to propagate such error and while I get the error in the console, there is no way to actually do something with it.

I assume that while this works, it is not meant to actually be used for serious software and I need to provide a context with anyerror on it for when I want to get errors from such tasks?

I think this part of the standard library is still a work-in-progress. I’m sure the team could give you a better idea as to the design philosophy of std.Thread. It may be intentional that you are unable to use the return value in the main thread. As of 0.8 you could do something like:

const std = @import("std");

const ThreadError = error {
    OOPS,
};

fn other(foo: *ThreadError!u64) void {
    foo.* = ThreadError.OOPS;
}

pub fn main() !void {
    var foo: ThreadError!u64 = undefined;
    var trd = try std.Thread.spawn(other, &foo);
    trd.wait();

    if (foo) |yay| {
        //...
    } else |darn| {
        try std.io.getStdOut().writeAll("We got an error\n");
    }
}