properly print config errors when loading config file

This commit is contained in:
Luna 2022-12-07 15:30:22 -03:00
parent 2d2a68b1c3
commit 8354478e72
3 changed files with 13 additions and 8 deletions

View file

@ -114,10 +114,11 @@ local function loadConfigFile()
local config_file_function = assert(loadstring(config_file_data)) local config_file_function = assert(loadstring(config_file_data))
local config_object = config_file_function() local config_object = config_file_function()
local schema_errors = validateConfigFile(config_object) local schema_errors = validateConfigFile(config_object)
if schema_errors then
for name, errors in pairs(schema_errors) do local total_count = table.pprint(schema_errors, {call=function() end})
log('CONFIG ERROR' .. writeSchemaErrors(errors, log)) if total_count > 0 then
end log('CONFIG ERROR')
table.pprint(schema_errors, {call=log})
end end
return config_object return config_object
end end

View file

@ -8,6 +8,7 @@
local ctx = require('ctx') local ctx = require('ctx')
local config = require('config') local config = require('config')
require('util')
ctx:loadFromConfig(config.loadConfigFile()) ctx:loadFromConfig(config.loadConfigFile())

View file

@ -4,21 +4,24 @@ function table.len(t)
return count return count
end end
function table.pprint(t, ident, total_count) function table.pprint(t, options, ident, total_count)
local ident = ident or 0 local ident = ident or 0
local total_count = total_count or 0 local total_count = total_count or 0
local options = options or {}
local print_function = options.call or print
if type(t) == 'table' then if type(t) == 'table' then
local count = 0 local count = 0
for k, v in pairs(t) do for k, v in pairs(t) do
print(string.rep('\t', ident) .. k) print_function(string.rep('\t', ident) .. k)
count = count + 1 count = count + 1
total_count = pprint(v, ident + 1, total_count) total_count = table.pprint(v, options, ident + 1, total_count)
end end
if count == 0 then if count == 0 then
--print('<empty table>') --print('<empty table>')
end end
else else
print(string.rep('\t', ident) .. tostring(t)) print_function(string.rep('\t', ident) .. tostring(t))
total_count = total_count + 1 total_count = total_count + 1
end end
return total_count return total_count