From 4f42c68a0a2fbdb0ee3671231d841953e900827c Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Wed, 15 Feb 2023 18:34:52 +0000 Subject: [PATCH] improve error message when parsing zls.json (#1002) --- src/configuration.zig | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/configuration.zig b/src/configuration.zig index b7f00d3..ff211e8 100644 --- a/src/configuration.zig +++ b/src/configuration.zig @@ -5,6 +5,7 @@ const tracy = @import("tracy.zig"); const known_folders = @import("known-folders"); const Config = @import("Config.zig"); +const offsets = @import("offsets.zig"); const logger = std.log.scoped(.config); @@ -27,9 +28,14 @@ pub fn loadFromFile(allocator: std.mem.Allocator, file_path: []const u8) ?Config var token_stream = std.json.TokenStream.init(file_buf); const parse_options = std.json.ParseOptions{ .allocator = allocator, .ignore_unknown_fields = true }; - // TODO: Better errors? Doesn't seem like std.json can provide us positions or context. + // TODO: use a better error reporting system or use ZON instead of JSON + // TODO: report errors using "textDocument/publishDiagnostics" var config = std.json.parse(Config, &token_stream, parse_options) catch |err| { - logger.warn("Error while parsing configuration file: {}", .{err}); + const loc = std.zig.findLineColumn(file_buf, token_stream.i); + logger.warn("{s}:{d}:{d}: Error while parsing configuration file {}", .{ file_path, loc.line + 1, loc.column, err }); + if (err == error.InvalidValueBegin) { + logger.warn("Maybe your configuration file contains a trailing comma", .{}); + } return null; };