Skip to content

IndexOutOfBoundsException in Traceback LastPosition getter when code called by Lua throws #98

@CodeSmile-0000011110110111

Description

I have overridden (replaced) dofile in order to make it use only paths relative to the application. If within that dofile an exception is thrown (ie FileNotFound), I always got an IndexOutOfBoundsException.

I investigated, built the project with PDB, and found the culprit to be in the Traceback class' LastPosition getter. Near the end, it returns one of the indexes of SourcePositions:

var p = closure.Proto;
return p.SourcePositions[frame.CallerInstructionIndex];

It seems that frame.CallerInstructionIndex is negative in my case (I have not further investigated as to why). I would suggest to add an in-range check, this fixed the issue for me and since then I get proper error messages:

var p = closure.Proto;
if (frame.CallerInstructionIndex >= 0 && frame.CallerInstructionIndex < p.SourcePositions.Length)
    return p.SourcePositions[frame.CallerInstructionIndex];

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions