mirror of https://github.com/fairyglade/ly.git
Log more detailed config error messages (closes #801)
Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
parent
3edd1ff1be
commit
cee0e0ca4b
|
@ -9,8 +9,8 @@
|
|||
.hash = "clap-0.11.0-oBajB-HnAQDPCKYzwF7rO3qDFwRcD39Q0DALlTSz5H7e",
|
||||
},
|
||||
.zigini = .{
|
||||
.url = "https://github.com/AnErrupTion/zigini/archive/d580d42f1b1051c0a35d63ab0f5704c6340e0bd3.tar.gz",
|
||||
.hash = "zigini-0.3.2-BSkB7aVHAADhxwo0aEdWtNzaVXer3d8RwXMuZd-q-spO",
|
||||
.url = "https://github.com/AnErrupTion/zigini/archive/96ca1d9f1a7ec741f07ceb104dae2b3a7bdfd48a.tar.gz",
|
||||
.hash = "zigini-0.3.2-BSkB7WJJAADybd5DGd9MLCp6ikGGUq9wicxsjv0HF1Qc",
|
||||
},
|
||||
.termbox2 = .{
|
||||
.url = "git+https://github.com/AnErrupTion/termbox2?ref=master#290ac6b8225aacfd16851224682b851b65fcb918",
|
||||
|
|
35
src/main.zig
35
src/main.zig
|
@ -53,6 +53,14 @@ fn ttyControlTransferSignalHandler(_: c_int) callconv(.c) void {
|
|||
_ = termbox.tb_shutdown();
|
||||
}
|
||||
|
||||
const ConfigError = struct {
|
||||
type_name: []const u8,
|
||||
key: []const u8,
|
||||
value: []const u8,
|
||||
error_name: []const u8,
|
||||
};
|
||||
var config_errors: std.ArrayList(ConfigError) = .empty;
|
||||
|
||||
pub fn main() !void {
|
||||
var shutdown = false;
|
||||
var restart = false;
|
||||
|
@ -154,6 +162,7 @@ pub fn main() !void {
|
|||
|
||||
config = config_ini.readFileToStruct(config_path, .{
|
||||
.fieldHandler = migrator.configFieldHandler,
|
||||
.errorHandler = configErrorHandler,
|
||||
.comment_characters = comment_characters,
|
||||
}) catch |err| load_error: {
|
||||
maybe_config_load_error = err;
|
||||
|
@ -187,6 +196,7 @@ pub fn main() !void {
|
|||
|
||||
config = config_ini.readFileToStruct(config_path, .{
|
||||
.fieldHandler = migrator.configFieldHandler,
|
||||
.errorHandler = configErrorHandler,
|
||||
.comment_characters = comment_characters,
|
||||
}) catch |err| load_error: {
|
||||
maybe_config_load_error = err;
|
||||
|
@ -307,6 +317,22 @@ pub fn main() !void {
|
|||
// 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 log_writer.print("unable to parse config file: {s}\n", .{@errorName(err)});
|
||||
|
||||
defer config_errors.deinit(temporary_allocator);
|
||||
|
||||
for (0..config_errors.items.len) |i| {
|
||||
const config_error = config_errors.items[i];
|
||||
defer {
|
||||
temporary_allocator.free(config_error.type_name);
|
||||
temporary_allocator.free(config_error.key);
|
||||
temporary_allocator.free(config_error.value);
|
||||
}
|
||||
|
||||
try log_writer.print("failed to convert value '{s}' of option '{s}' to type '{s}': {s}\n", .{ config_error.value, config_error.key, config_error.type_name, config_error.error_name });
|
||||
|
||||
// Flush immediately so we can free the allocated memory afterwards
|
||||
try log_writer.flush();
|
||||
}
|
||||
}
|
||||
|
||||
if (!could_open_log_file) {
|
||||
|
@ -968,6 +994,15 @@ pub fn main() !void {
|
|||
}
|
||||
}
|
||||
|
||||
fn configErrorHandler(type_name: []const u8, key: []const u8, value: []const u8, err: anyerror) void {
|
||||
config_errors.append(temporary_allocator, .{
|
||||
.type_name = temporary_allocator.dupe(u8, type_name) catch return,
|
||||
.key = temporary_allocator.dupe(u8, key) catch return,
|
||||
.value = temporary_allocator.dupe(u8, value) catch return,
|
||||
.error_name = @errorName(err),
|
||||
}) catch return;
|
||||
}
|
||||
|
||||
fn ttyClearScreen() !void {
|
||||
// Clear the TTY because termbox2 doesn't seem to do it properly
|
||||
const capability = termbox.global.caps[termbox.TB_CAP_CLEAR_SCREEN];
|
||||
|
|
Loading…
Reference in New Issue