Script error location - #385
Merged
Merged
Conversation
There was a problem hiding this comment.
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_errorutilities 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 withlegacy::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,
findIdentifierInPluginSourcewill 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.
ShrBox
approved these changes
Aug 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.

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