Skip to content

Conversation

akapug
Copy link
Member

@akapug akapug commented Sep 10, 2025

Ready for review Powered by Pull Request Badge

Summary

  • Prefer the top guest JS frame's SourceSection when rendering error context, especially for host exceptions raised via Polyglot (e.g., invokeMember failures). This aligns the highlighted line with the actual call site in guest code.
  • Fix context math in errorContextLines (proper base offset and inclusive range length), preventing off-by-one and unrelated line highlights.
  • Keep polyglot context in the renderer for host exceptions (avoid converting to plain host Throwable for display), so we can still show guest code context and language-aware highlighting.
  • Add a test validating error line mapping for guest-thrown Error (ensures no regressions on guest exceptions).

Why
Issue #1595: JS errors surfaced from host code were showing incorrect source locations (e.g., pointing to an unrelated previous line). The polyglot stack already contains the correct guest frame; we were not using it for context selection.

Details

  • ToolShellCommand.kt
    • Introduce errorContextLines(SourceSection?) and delegate from the existing overload.
    • Compute bestSection = top guest frame's sourceLocation or fallback to exc.sourceLocation.
    • Use bestSection for context extraction and line-range computation.
    • Correct base/total range calculations (0-based slicing, inclusive end).
    • In processUserCodeError, for non-GuestError host exceptions, keep and render the original PolyglotException so the code box is shown with proper guest context.
  • Tests
    • New test ElideToolErrorLocationTest validates that a guest-side thrown Error highlights the correct line, guarding against regressions in the refactor.

Notes

  • A follow-up test specifically for a host-exception path can be added using a module call that intentionally fails at the host (e.g., Node http.createServer); this depends on test runtime availability of the module. The structural changes here fix that path by selecting the top guest frame.

Closes #1595.

…t context math; keep polyglot context for host exceptions; add error location test (#1595)
@akapug akapug requested a review from sgammon as a code owner September 10, 2025 23:51
…gine(cli): allow disabling sqlite natives on JVM via system/env flags for tests\nexec: add compileOnly graalvm.svm for ImageInfo.inImageCode() reference\n\nRefs #1595
@akapug
Copy link
Member Author

akapug commented Sep 11, 2025

Added a follow-up commit to stabilize local JVM test runs and align the assertion with actual CLI output:

  • test(cli): broaden error marker assertion to accept either the arrow (\u2192) or cross (\u2717) marker
  • engine(cli): allow disabling SQLite native loading on JVM via system/env flags (elide.disable.sqlite, elide.disableNatives, ELIDE_DISABLE_SQLITE, ELIDE_DISABLE_NATIVES) to keep tests hermetic
  • exec: add compileOnly graalvm.svm for ImageInfo.inImageCode() during JVM builds

Local validation (WSL, Java 24):

./gradlew :packages:cli:test --tests "elide.tool.cli.ElideToolErrorLocationTest" \
  -x :packages:graalvm:natives -x buildThirdPartyNatives -x buildRustNativesForHost -x buildRustNativesForHostRelease \
  -x spotlessApply -x detekt --no-build-cache --stacktrace

Result: 1 passing (targeted test). CI will verify across environments. Refs #1595.

Copy link

codecov bot commented Sep 11, 2025

Codecov Report

❌ Patch coverage is 37.50000% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 40.57%. Comparing base (5a2cc4e) to head (4cc1b49).

Files with missing lines Patch % Lines
...kotlin/elide/tool/cli/cmd/repl/ToolShellCommand.kt 37.50% 6 Missing and 9 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1636      +/-   ##
==========================================
+ Coverage   39.98%   40.57%   +0.58%     
==========================================
  Files         783      783              
  Lines       37433    37439       +6     
  Branches     5295     5298       +3     
==========================================
+ Hits        14969    15191     +222     
+ Misses      20675    20387     -288     
- Partials     1789     1861      +72     
Flag Coverage Δ
jvm 40.57% <37.50%> (+0.58%) ⬆️
lib 40.57% <37.50%> (+0.58%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...kotlin/elide/tool/cli/cmd/repl/ToolShellCommand.kt 37.90% <37.50%> (+7.13%) ⬆️

... and 7 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5a2cc4e...4cc1b49. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

JavaScript: error messages show incorrect source location

1 participant