Skip to content

Script error location - #385

Merged
ShrBox merged 3 commits into
LiteLDev:developfrom
xianyubb:script-error-location
Aug 24, 2026
Merged

Script error location#385
ShrBox merged 3 commits into
LiteLDev:developfrom
xianyubb:script-error-location

Conversation

@xianyubb

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR aims to locate the exact position of code errors, addressing the difficulty in debugging the lse plugin caused by the huge codebase making it hard to pinpoint precise error points during development.Especially for Node.js plugins, there are almost no error prompts.

However, to enable this feature, corresponding adjustments to ScriptX are also required.
I will submit a PR to ScriptX at the same time. Link:LiteLDev/ScriptX#20

Which issues does this PR resolve?

This PR solves the above‑mentioned issues and provides clear error code hints.
8ffd7e42dd1400e4f0cec1b11850ab93

Checklist before merging

Thank you for your contribution to the repository.
Before submitting this PR, please make sure:

  • Your code builds clean without any errors or warnings
  • Your code follows LeviLamina C++ Style Guide
  • You have tested all functions
  • You have not used code without license
  • You have added statement for third-party code

Copilot AI lite review requested due to automatic review settings August 23, 2026 21:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces enhanced script exception reporting to help plugin developers pinpoint the exact script source location (file/line/column + nearby source lines) when errors occur, and wires the new reporting into existing catch/exception paths across the engine.

Changes:

  • Added legacy::script_error utilities to parse stack traces and print a “Script error location” block, plus a helper to rethrow/print the current exception.
  • Replaced multiple ll::error_utils::* calls with legacy::script_error::* so script exceptions get location-aware output consistently.
  • Enabled V8 uncaught exception stack capture for Node.js engines.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/lse/Entry.cpp Switch load error printing to the new script-aware exception printer.
src/legacy/utils/ScriptErrorPrinter.h New public header for script error location printing APIs.
src/legacy/utils/ScriptErrorPrinter.cpp New implementation: stack parsing + source lookup + formatted location/snippet logging.
src/legacy/main/PythonHelper.cpp Route Python debug-engine exception printing through the new printer.
src/legacy/main/NodeJsHelper.cpp Enable V8 stack capture; print script location for Node load errors.
src/legacy/main/BuiltinCommands.cpp Route debug command exception printing through the new printer.
src/legacy/engine/TimeTaskSystem.cpp Use new exception printer in task exception paths.
src/legacy/engine/RemoteCall.cpp Use new exception printer for remote call script exceptions and unknown exceptions.
src/legacy/engine/MessageSystem.cpp Use new exception printer throughout message dispatch exception handling.
src/legacy/api/SystemAPI.cpp Use new exception printer in NewProcess callback exception handling.
src/legacy/api/NetworkAPI.cpp Use new exception printer in network-related exception handling.
src/legacy/api/LegacyCommandAPI.cpp Use new exception printer for legacy command registration failures.
src/legacy/api/EventAPI.h Update event callback exception macro usage and exception printing.
src/legacy/api/EventAPI.cpp Use new exception printer in basic event listener initialization.
src/legacy/api/APIHelp.h Centralize macros onto new printer; add API-name-aware logging macro variant.
src-server/lse/PluginManager.cpp Print script exception details when plugin load fails.
src-client/lse/PluginManager.cpp Print script exception details when plugin enable fails.
Suppressed comments (2)

src/legacy/utils/ScriptErrorPrinter.cpp:109

  • The fallback source lookup scans the plugin directory recursively (up to 5000 entries) every time a file isn’t found directly. On large plugins this can make exception handling noticeably expensive; consider caching filename→path results (per plugin) or avoiding the recursive scan unless an explicit debug/diagnostic mode is enabled.
    size_t visited = 0;
    for (std::filesystem::recursive_directory_iterator it{
             root,
             std::filesystem::directory_options::skip_permission_denied,
             ec

src/legacy/utils/ScriptErrorPrinter.cpp:185

  • When no stack frame is parsed, findIdentifierInPluginSource will recursively scan up to 5000 files looking for an identifier on every error. This worst-case O(files × lines) work can be very expensive in production; consider caching/search indexing, throttling, or making this heuristic conditional (e.g., only for ReferenceError cases and/or under a debug flag).
    std::error_code ec;
    size_t          visited = 0;
    for (std::filesystem::recursive_directory_iterator it{
             root,
             std::filesystem::directory_options::skip_permission_denied,

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/legacy/utils/ScriptErrorPrinter.h
Comment thread src/legacy/utils/ScriptErrorPrinter.cpp
@ShrBox
ShrBox merged commit 16f3de8 into LiteLDev:develop Aug 24, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants