Attempt to index nil Table with '...' Error Output at wrong line

local Table = {}

Table.SubTable["Key"] = {
	Key1 = "Value1",
	Key2 = "Value2",
	Key3 = "Value3",
	Key4 = "Value4",
}

Output

ServerScriptService.Script:7: attempt to index nil with ‘Key’
Script ‘ServerScriptService.Script’, Line 7

Expected Output is

ServerScriptService.Script:3: attempt to index nil with ‘Key’
Script ‘ServerScriptService.Script’, Line 3

YES, Table.SubTable is nil but that is NOT the point!


Very simple to reproduce,

  1. first copy the script
  2. paste it into the Command Bar of any game
  3. run it
  4. observe the error
3 Likes

I tried your code in replit, here’s the output:

lua: [string "<eval>"]:8: attempt to index field 'SubTable' (a nil value)
stack traceback:
    [string "<eval>"]:8: in main chunk

This happens with any statement that goes over multiple lines. For some reason they always return the line just before the last, e.g. 7 in your case where the statement ends on 8.

Similar thing happens if you call nil values:

local var = nil
local results = var(
	'test-param'
)

Errors on line 3, one before the end of the statement - not line 2 where it started or line 4 where it ended.
image

I don’t know if this behaviour is “wrong” as you state, or whether this is expected for statements like this.

I don’t know either but it’s confusing and cost precious Development time.

The Output messages especially for Errors should be Easily understood and precise, which isn’t the case at the moment.

Would it make sense to you at it’s current state? Maybe but I don’t think the majority can agree with that.

I agree it’s not great. I just wonder if it’s a bug or if it’s intentional. If it isn’t a bug then this should definitely be a feature request. I assume an engineer will confirm either way soon.

It would definitely make more sense to be at the start, even if the problem was further in the statement it’s still better than being near the end. If it’s at the start then you’d logically look through the whole statement.

The reason the error says line 7 instead of 3 is because of the fact that you spread it out over multiple lines, so it just uses the last line of it, not including the closing brace. This doesn’t seem like incorrect behaviour, although it may seem a bit odd.

1 Like

We’ll take a look at this.

Vanilla Lua sets the line info to be the last line of the entire expression for calls and table literals. We could do this, but it doesn’t seem optimal necessarily - it seems better to reset the line number so that the report is exactly at the line where assignment is computed. However, this may make stepping through the code somewhat less convenient - not sure yet how we’ll fix this.

2 Likes