diff --git a/src/lua/Api.zig b/src/lua/Api.zig index 66b0b14..81f560e 100644 --- a/src/lua/Api.zig +++ b/src/lua/Api.zig @@ -2,6 +2,8 @@ const std = @import("std"); const zlua = @import("zlua"); const wlr = @import("wlroots"); +const Utils = @import("../Utils.zig"); + const gpa = std.heap.c_allocator; const env_map = &@import("../main.zig").env_map; @@ -14,8 +16,9 @@ pub fn spawn(L: *zlua.Lua) i32 { var child = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", cmd }, gpa); child.env_map = env_map; - child.spawn() catch { - L.raiseErrorStr("Unable to spawn process", .{}); // TODO: Give more descriptive error + child.spawn() catch |err| switch (err) { + error.OutOfMemory => Utils.oomPanic(), + else => L.raiseErrorStr("Unable to spawn process child process", .{}), }; L.pushNil(); diff --git a/src/lua/Fs.zig b/src/lua/Fs.zig index 64bfa6a..498f41a 100644 --- a/src/lua/Fs.zig +++ b/src/lua/Fs.zig @@ -4,6 +4,7 @@ const std = @import("std"); const zlua = @import("zlua"); const Lua = @import("Lua.zig"); +const Utils = @import("../Utils.zig"); const gpa = std.heap.c_allocator; @@ -17,9 +18,7 @@ pub fn joinpath(L: *zlua.Lua) i32 { return 0; } - var paths = std.ArrayList([:0]const u8).initCapacity(gpa, @intCast(nargs)) catch { - return 0; - }; + var paths = std.ArrayList([:0]const u8).initCapacity(gpa, @intCast(nargs)) catch Utils.oomPanic(); defer paths.deinit(gpa); var i: u8 = 1; @@ -30,17 +29,12 @@ pub fn joinpath(L: *zlua.Lua) i32 { } const partial_path = L.toString(i) catch unreachable; - paths.append(gpa, partial_path) catch { - // TODO: tell lua? - return 0; - }; + paths.append(gpa, partial_path) catch Utils.oomPanic(); } - const final_path: []const u8 = std.fs.path.join(gpa, paths.items) catch { - // TODO: tell lua? - return 0; - }; - _ = L.pushString(final_path); + const final_path: []const u8 = std.fs.path.join(gpa, paths.items) catch Utils.oomPanic(); + defer gpa.free(final_path); + _ = L.pushString(final_path); return 1; } diff --git a/src/lua/Hook.zig b/src/lua/Hook.zig index ff19a22..e128c27 100644 --- a/src/lua/Hook.zig +++ b/src/lua/Hook.zig @@ -39,9 +39,7 @@ pub fn add(L: *zlua.Lua) i32 { _ = L.pushString("callback"); _ = L.getTable(2); if (L.isFunction(-1)) { - hook.options.lua_cb_ref_idx = L.ref(zlua.registry_index) catch { - L.raiseErrorStr("Lua error check your config", .{}); // TODO: Give more descriptive error - }; + hook.options.lua_cb_ref_idx = try L.ref(zlua.registry_index); } try server.hooks.append(gpa, hook); diff --git a/src/lua/Input.zig b/src/lua/Input.zig index 8752c55..ff43040 100644 --- a/src/lua/Input.zig +++ b/src/lua/Input.zig @@ -41,17 +41,13 @@ pub fn add_keymap(L: *zlua.Lua) i32 { _ = L.pushString("press"); _ = L.getTable(3); if (L.isFunction(-1)) { - keymap.options.lua_press_ref_idx = L.ref(zlua.registry_index) catch { - L.raiseErrorStr("Lua error check your config", .{}); // TODO: Insert more descrptive errors - }; + keymap.options.lua_press_ref_idx = L.ref(zlua.registry_index) catch Utils.oomPanic(); } _ = L.pushString("release"); _ = L.getTable(3); if (L.isFunction(-1)) { - keymap.options.lua_release_ref_idx = L.ref(zlua.registry_index) catch { - L.raiseErrorStr("Lua error check your config", .{}); // TODO: Insert more descrptive errors - }; + keymap.options.lua_release_ref_idx = L.ref(zlua.registry_index) catch Utils.oomPanic(); } _ = L.pushString("repeat");