mirror of https://github.com/fairyglade/ly.git
Log error name when zigini fails to parse config
Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
parent
145ad5142c
commit
3edd1ff1be
22
src/main.zig
22
src/main.zig
|
@ -111,7 +111,7 @@ pub fn main() !void {
|
||||||
var config: Config = undefined;
|
var config: Config = undefined;
|
||||||
var lang: Lang = undefined;
|
var lang: Lang = undefined;
|
||||||
var save: Save = undefined;
|
var save: Save = undefined;
|
||||||
var config_load_failed = false;
|
var maybe_config_load_error: ?anyerror = null;
|
||||||
var can_get_lock_state = true;
|
var can_get_lock_state = true;
|
||||||
var can_draw_clock = true;
|
var can_draw_clock = true;
|
||||||
|
|
||||||
|
@ -155,9 +155,9 @@ pub fn main() !void {
|
||||||
config = config_ini.readFileToStruct(config_path, .{
|
config = config_ini.readFileToStruct(config_path, .{
|
||||||
.fieldHandler = migrator.configFieldHandler,
|
.fieldHandler = migrator.configFieldHandler,
|
||||||
.comment_characters = comment_characters,
|
.comment_characters = comment_characters,
|
||||||
}) catch _config: {
|
}) catch |err| load_error: {
|
||||||
config_load_failed = true;
|
maybe_config_load_error = err;
|
||||||
break :_config Config{};
|
break :load_error Config{};
|
||||||
};
|
};
|
||||||
|
|
||||||
const lang_path = try std.fmt.allocPrint(allocator, "{s}{s}lang/{s}.ini", .{ s, trailing_slash, config.lang });
|
const lang_path = try std.fmt.allocPrint(allocator, "{s}{s}lang/{s}.ini", .{ s, trailing_slash, config.lang });
|
||||||
|
@ -179,7 +179,7 @@ pub fn main() !void {
|
||||||
}) catch migrator.tryMigrateSaveFile(&user_buf);
|
}) catch migrator.tryMigrateSaveFile(&user_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!config_load_failed) {
|
if (maybe_config_load_error == null) {
|
||||||
migrator.lateConfigFieldHandler(&config);
|
migrator.lateConfigFieldHandler(&config);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -188,9 +188,9 @@ pub fn main() !void {
|
||||||
config = config_ini.readFileToStruct(config_path, .{
|
config = config_ini.readFileToStruct(config_path, .{
|
||||||
.fieldHandler = migrator.configFieldHandler,
|
.fieldHandler = migrator.configFieldHandler,
|
||||||
.comment_characters = comment_characters,
|
.comment_characters = comment_characters,
|
||||||
}) catch _config: {
|
}) catch |err| load_error: {
|
||||||
config_load_failed = true;
|
maybe_config_load_error = err;
|
||||||
break :_config Config{};
|
break :load_error Config{};
|
||||||
};
|
};
|
||||||
|
|
||||||
const lang_path = try std.fmt.allocPrint(allocator, "{s}/ly/lang/{s}.ini", .{ build_options.config_directory, config.lang });
|
const lang_path = try std.fmt.allocPrint(allocator, "{s}/ly/lang/{s}.ini", .{ build_options.config_directory, config.lang });
|
||||||
|
@ -209,7 +209,7 @@ pub fn main() !void {
|
||||||
}) catch migrator.tryMigrateSaveFile(&user_buf);
|
}) catch migrator.tryMigrateSaveFile(&user_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!config_load_failed) {
|
if (maybe_config_load_error == null) {
|
||||||
migrator.lateConfigFieldHandler(&config);
|
migrator.lateConfigFieldHandler(&config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -303,10 +303,10 @@ pub fn main() !void {
|
||||||
var info_line = InfoLine.init(allocator, &buffer);
|
var info_line = InfoLine.init(allocator, &buffer);
|
||||||
defer info_line.deinit();
|
defer info_line.deinit();
|
||||||
|
|
||||||
if (config_load_failed) {
|
if (maybe_config_load_error) |err| {
|
||||||
// We can't localize this since the config failed to load so we'd fallback to the default language anyway
|
// We can't localize this since the config failed to load so we'd fallback to the default language anyway
|
||||||
try info_line.addMessage("unable to parse config file", config.error_bg, config.error_fg);
|
try info_line.addMessage("unable to parse config file", config.error_bg, config.error_fg);
|
||||||
try log_writer.writeAll("unable to parse config file\n");
|
try log_writer.print("unable to parse config file: {s}\n", .{@errorName(err)});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!could_open_log_file) {
|
if (!could_open_log_file) {
|
||||||
|
|
Loading…
Reference in New Issue