From ced6201cb0433c11d8b7ca9e60de61b133cc8fab Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Mon, 9 Jan 2023 03:25:06 -0800 Subject: Cleanup error handling in Bun.listen --- src/linux_c.zig | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/linux_c.zig') diff --git a/src/linux_c.zig b/src/linux_c.zig index 2ff96c966..b652a6490 100644 --- a/src/linux_c.zig +++ b/src/linux_c.zig @@ -141,6 +141,20 @@ pub const SystemErrno = enum(u8) { pub const max = 134; + pub fn init(code: anytype) ?SystemErrno { + if (comptime std.meta.trait.isSignedInt(@TypeOf(code))) { + if (code < 0) + return init(-code); + } + + if (code >= max) return null; + return @intToEnum(SystemErrno, code); + } + + pub fn label(this: SystemErrno) ?[]const u8 { + return labels.get(this) orelse null; + } + const LabelMap = std.EnumMap(SystemErrno, []const u8); pub const labels: LabelMap = brk: { var map: LabelMap = LabelMap.initFull(""); -- cgit v1.2.3