Skip to content

debug.traceback failed on anonymous function #1665

@ChouUn

Description

@ChouUn

let [result] = string.gsub(trace, "(%S+)%.lua:(%d+)", (file, line) =>

When anonymous functions are included in TS code, stack.traceback printing doesn't work exactly as expected, such as in the form SOME_PATH\dist\main.ts:43: in function <SOME_PATH\dist\main.lua:65>.
This is because the "<" escapes as a non-whitespace character matching the %S, causing it to be considered part of the path.

On Windows, you can quickly fix this by changing the pattern to ([^%s<]+)%.lua:(%d+).
This isn't the most elegant fix, considering that "<" can be part of a filename on Unix-like systems.

Additional, my guess is that if there are spaces in the entire path, it may also cause unexpected behavior because of %S.

However, collecting the paths to build a regular expression can be quite risky.
Do you have any suggestions?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions