NattLua icon indicating copy to clipboard operation
NattLua copied to clipboard

Improve error messages

Open CapsAdmin opened this issue 5 years ago • 1 comments

At the moment error messages are a bit all over the place. In some cases the token nodes that the error points to is also not always correct.

I've thought about representing errors with a "because chain", not sure if this is practically useful or if it's just a neat idea. Something like this:

local A = {
    foo = true,
    bar = false,
    faz = {
        one = 1,
        two = 2,
    }
}

local B = {
    foo = true,
    bar = false,
    faz = {
        one = 1,
        two = 3,
    }
}

A is not a subset of B because
A.faz is not a subset of B.faz because
A.faz.two is not a subset of B.faz.two because
2 is not the same literal as 3

It's a bit similar to a stack trace. The problem I have with stack traces is that it's not always useful to see all of the stack, but figuring out which level to cut out is not easily solvable.

CapsAdmin avatar Oct 31 '20 09:10 CapsAdmin

I started doing this and it feels easier to me to read than i was expecting. Especially when it's split in newlines.

At the moment, this case is obviously too verbose

_G does not contain "Token" 
because "Token" is not the same value as "__name"
"Token" is not the same value as "return_type"
"Token" is not the same value as "argument_type"
"Token" is not the same value as "exclude"
"Token" is not the same value as "Tuple"
"Token" is not the same value as "enum"
"Token" is not the same value as "error_inside_base_environment"
"Token" is not the same value as "keysof"
"Token" is not the same value as "type_assert"
"Token" is not the same value as "subset_of"
-- ETC

I'm thinking I should embrace verbosity and then simplify the message when displaying the error.

Random quick thought, maybe even use a "language" that is easily parsable that then generates the proper error in English.

"Token" not in _G:
_G["Token"] != "__name",
_G["Token"] != "__name",
_G["Token"] != "__name",
-- ETC

CapsAdmin avatar Dec 21 '20 23:12 CapsAdmin