properly print config errors when loading config file
This commit is contained in:
parent
2d2a68b1c3
commit
8354478e72
3 changed files with 13 additions and 8 deletions
|
@ -114,10 +114,11 @@ local function loadConfigFile()
|
|||
local config_file_function = assert(loadstring(config_file_data))
|
||||
local config_object = config_file_function()
|
||||
local schema_errors = validateConfigFile(config_object)
|
||||
if schema_errors then
|
||||
for name, errors in pairs(schema_errors) do
|
||||
log('CONFIG ERROR' .. writeSchemaErrors(errors, log))
|
||||
end
|
||||
|
||||
local total_count = table.pprint(schema_errors, {call=function() end})
|
||||
if total_count > 0 then
|
||||
log('CONFIG ERROR')
|
||||
table.pprint(schema_errors, {call=log})
|
||||
end
|
||||
return config_object
|
||||
end
|
||||
|
|
1
main.lua
1
main.lua
|
@ -8,6 +8,7 @@
|
|||
|
||||
local ctx = require('ctx')
|
||||
local config = require('config')
|
||||
require('util')
|
||||
|
||||
ctx:loadFromConfig(config.loadConfigFile())
|
||||
|
||||
|
|
11
util.lua
11
util.lua
|
@ -4,21 +4,24 @@ function table.len(t)
|
|||
return count
|
||||
end
|
||||
|
||||
function table.pprint(t, ident, total_count)
|
||||
function table.pprint(t, options, ident, total_count)
|
||||
local ident = ident 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
|
||||
local count = 0
|
||||
for k, v in pairs(t) do
|
||||
print(string.rep('\t', ident) .. k)
|
||||
print_function(string.rep('\t', ident) .. k)
|
||||
count = count + 1
|
||||
total_count = pprint(v, ident + 1, total_count)
|
||||
total_count = table.pprint(v, options, ident + 1, total_count)
|
||||
end
|
||||
if count == 0 then
|
||||
--print('<empty table>')
|
||||
end
|
||||
else
|
||||
print(string.rep('\t', ident) .. tostring(t))
|
||||
print_function(string.rep('\t', ident) .. tostring(t))
|
||||
total_count = total_count + 1
|
||||
end
|
||||
return total_count
|
||||
|
|
Loading…
Reference in a new issue