fix: no logner crashes when config directory is missing

This commit is contained in:
LordMZTE 2022-05-28 16:59:39 +02:00
parent 10ae6933ba
commit 4cc0ba139a
1 changed files with 4 additions and 2 deletions

View File

@ -24,14 +24,16 @@ pub const Config = struct {
) catch break :toml orelse break :toml;
defer config_dir.close();
const config = try config_dir.realpathAlloc(alloc, "gpower2/config.toml");
const config = config_dir.realpathAlloc(alloc, "gpower2/config.toml") catch {
std.log.warn("Couldn't open config directory, skipping config", .{});
break :toml;
};
defer alloc.free(config);
const config_z = try std.cstr.addNullByte(alloc, config);
defer alloc.free(config_z);
const c_file = c.fopen(config_z, "r");
std.log.debug("{x}", .{@ptrToInt(c_file)});
if (c_file == null) {
std.log.warn("Opening config failed, skipping config", .{});
break :toml;