1
0

Improved error messages, and fixed issue with importing from other modules

This commit is contained in:
Jon Michael Aanes 2017-04-05 12:21:43 +02:00
parent ae73cc9b64
commit ec3ba2cab9
3 changed files with 18 additions and 7 deletions

View File

@ -1,5 +1,10 @@
local TABLE_TYPE = require "table_type"
local TABLE_TYPE
do
local thispath = ... and select('1', ...):match('.+%.') or ''
was_loaded, TABLE_TYPE = pcall(require, thispath..'table_type')
assert(was_loaded, '[pretty]: Could not load vital library: table_type')
end
local RESERVED_LUA_WORDS = {
['and'] = true,
@ -147,7 +152,9 @@ function is_short_table (value)
-- Predicate: value is either an empty table, or one with a single simple
-- non-function element.
assert( type(value) == 'table', '[analyze_structure]: Only tables allowed!' )
if type(value) ~= 'table' then
error(('[pretty/internal]: Only tables allowed in function analyze_structure.is_short_table, but was given %s (%s)'):format(value, type(value)), 2)
end
local first_key = next(value, nil)
if not first_key then

View File

@ -102,7 +102,6 @@ end
local function format_function_with_closure (value, options, depth, l, format_value)
local info = get_function_info(value)
--assert(info.nups > 0)
local function_str = nil
if (info.defined_how == 'string') then
function_str = get_full_function_str(info.source, info.linedefined, info.lastlinedefined)

View File

@ -13,9 +13,10 @@ do
-- Load other stuff
local was_loaded
was_loaded, analyze_structure = pcall(require, thispath..'analyze_structure')
assert(was_loaded)
print(was_loaded, analyze_structure)
assert(was_loaded, '[pretty]: Could not load vital library: analyze_structure')
was_loaded, TABLE_TYPE = pcall(require, thispath..'table_type')
assert(was_loaded)
assert(was_loaded, '[pretty]: Could not load vital library: table_type')
end
--
@ -238,7 +239,9 @@ local SIMPLE_VALUE_TYPES = {
}
local function is_empty_table (value)
assert( type(value) == 'table', '[is_empty_table]: Only tables allowed!' )
if type(value) ~= 'table' then
error(('[pretty/internal]: Only tables allowed in function pretty.is_empty_table, but was given %s (%s)'):format(value, type(value)), 2)
end
return next(value) == nil
end
@ -246,7 +249,9 @@ local function is_short_table (value)
-- In this context, a short table is either an empty table, or one with a
-- single element.
assert( type(value) == 'table', '[is_short_table]: Only tables allowed!' )
if type(value) ~= 'table' then
error(('[pretty/internal]: Only tables allowed in function pretty.is_short_table, but was given %s (%s)'):format(value, type(value)), 2)
end
local first_key = next(value)
return (not first_key or SIMPLE_VALUE_TYPES[type(value[first_key])])