diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index 6469194029..5655c10b8e 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -3952,7 +3952,7 @@ inline fn MAKELANGID(p: c_ushort, s: c_ushort) LANGID { /// and you get an unexpected error. pub fn unexpectedError(err: Win32Error) UnexpectedError { @branchHint(.cold); - if (std.posix.unexpected_error_tracing) { + if (std.options.unexpected_error_tracing) { std.debug.print("error.Unexpected: GetLastError({d}): {t}\n", .{ err, err }); std.debug.dumpCurrentStackTrace(.{ .first_address = @returnAddress() }); } @@ -3962,7 +3962,7 @@ pub fn unexpectedError(err: Win32Error) UnexpectedError { /// Call this when you made a windows NtDll call /// and you get an unexpected status. pub fn unexpectedStatus(status: NTSTATUS) UnexpectedError { - if (std.posix.unexpected_error_tracing) { + if (std.options.unexpected_error_tracing) { std.debug.print("error.Unexpected NTSTATUS=0x{x} ({s})\n", .{ @intFromEnum(status), std.enums.tagName(NTSTATUS, status) orelse "", diff --git a/lib/std/posix.zig b/lib/std/posix.zig index 87af625e44..f61293e20e 100644 --- a/lib/std/posix.zig +++ b/lib/std/posix.zig @@ -686,7 +686,7 @@ pub fn munmap(memory: []align(page_size_min) const u8) void { .SUCCESS => return, .INVAL => unreachable, // Invalid parameters. .NOMEM => unreachable, // Attempted to unmap a region in the middle of an existing mapping. - else => |e| if (unexpected_error_tracing) { + else => |e| if (std.options.unexpected_error_tracing) { std.debug.panic("unexpected errno: {d} ({t})", .{ @intFromEnum(e), e }); } else unreachable, } @@ -1662,22 +1662,12 @@ pub fn name_to_handle_atZ( pub const lfs64_abi = native_os == .linux and builtin.link_libc and (builtin.abi.isGnu() or builtin.abi.isAndroid()); -/// Whether or not `error.Unexpected` will print its value and a stack trace. -/// -/// If this happens the fix is to add the error code to the corresponding -/// switch expression, possibly introduce a new error in the error set, and -/// send a patch to Zig. -pub const unexpected_error_tracing = builtin.mode == .Debug and switch (builtin.zig_backend) { - .stage2_llvm, .stage2_x86_64 => true, - else => false, -}; - pub const UnexpectedError = std.Io.UnexpectedError; /// Call this when you made a syscall or something that sets errno /// and you get an unexpected error. pub fn unexpectedErrno(err: E) UnexpectedError { - if (unexpected_error_tracing) { + if (std.options.unexpected_error_tracing) { std.debug.print("unexpected errno: {d}\n", .{@intFromEnum(err)}); std.debug.dumpCurrentStackTrace(.{}); } diff --git a/lib/std/std.zig b/lib/std/std.zig index e700c728c1..a7b7daf664 100644 --- a/lib/std/std.zig +++ b/lib/std/std.zig @@ -180,6 +180,16 @@ pub const Options = struct { /// Allows disabling networking in std.Io implementations. networking: bool = true, + /// Whether or not `error.Unexpected` will print its value and a stack trace. + /// + /// If this happens the fix is to add the error code to the corresponding + /// switch expression, possibly introduce a new error in the error set, and + /// send a patch to Zig. + unexpected_error_tracing: bool = @import("builtin").mode == .Debug and switch (@import("builtin").zig_backend) { + .stage2_llvm, .stage2_x86_64 => true, + else => false, + }, + /// TODO This is a separate decl instead of a field as a workaround around /// compilation errors due to zig not being lazy enough. pub const logTerminalMode: fn () Io.Terminal.Mode = log.defaultTerminalMode; diff --git a/src/link/MachO.zig b/src/link/MachO.zig index a92522d93d..bbd26fd762 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -5133,7 +5133,7 @@ pub fn getKernError(err: std.c.kern_return_t) KernE { } pub fn unexpectedKernError(err: KernE) std.posix.UnexpectedError { - if (std.posix.unexpected_error_tracing) { + if (std.options.unexpected_error_tracing) { std.debug.print("unexpected error: {d}\n", .{@intFromEnum(err)}); std.debug.dumpCurrentStackTrace(.{}); }