[PR #948] [MERGED] Improve handling of errors when analysis fails #823

Closed
opened 2025-12-30 01:27:02 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/apple/pkl/pull/948
Author: @bioball
Created: 2/12/2025
Status: Merged
Merged: 2/13/2025
Merged by: @bioball

Base: mainHead: improve-analyze-import-errors


📝 Commits (3)

  • 5db648f Improve handling of errors when analysis fails
  • aa145bc Address review feedback
  • 7738181 Run spotless apply

📊 Changes

9 files changed (+127 additions, -57 deletions)

View changed files

📝 pkl-core/src/main/java/org/pkl/core/Analyzer.java (+1 -3)
📝 pkl-core/src/main/java/org/pkl/core/runtime/VmImportAnalyzer.java (+84 -47)
📝 pkl-core/src/main/java/org/pkl/core/stdlib/analyze/AnalyzeNodes.java (+2 -7)
pkl-core/src/test/files/LanguageSnippetTests/input-helper/analyze/cannotFindModule.pkl (+1 -0)
pkl-core/src/test/files/LanguageSnippetTests/input-helper/analyze/invalidGlob.pkl (+1 -0)
pkl-core/src/test/files/LanguageSnippetTests/input/errors/analyzeImportsCannotFindModule.pkl (+5 -0)
pkl-core/src/test/files/LanguageSnippetTests/input/errors/analyzeImportsInvalidGlob.pkl (+5 -0)
pkl-core/src/test/files/LanguageSnippetTests/output/errors/analyzeImportsCannotFindModule.err (+14 -0)
pkl-core/src/test/files/LanguageSnippetTests/output/errors/analyzeImportsInvalidGlob.err (+14 -0)

📄 Description

Modules that cannot be loaded for one reason or another will now include the offending import as part of the stack trace, with a clear error message.

Before:

–– Pkl Error ––
None (cause has no message)

x | res = analyze.importGraph(Set(reflect.Module(cannotFindModule).uri))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

After:

–– Pkl Error ––
Cannot find module `bogusModule.pkl`.

x | import "bogusModule.pkl"
           ^^^^^^^^^^^^^^^^^
at pkl.analyze#importGraph (file:///$snippetsDir/input-helper/analyze/cannotFindModule.pkl)

x | res = analyze.importGraph(Set(reflect.Module(cannotFindModule).uri))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Closes https://github.com/apple/pkl/pull/949


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/apple/pkl/pull/948 **Author:** [@bioball](https://github.com/bioball) **Created:** 2/12/2025 **Status:** ✅ Merged **Merged:** 2/13/2025 **Merged by:** [@bioball](https://github.com/bioball) **Base:** `main` ← **Head:** `improve-analyze-import-errors` --- ### 📝 Commits (3) - [`5db648f`](https://github.com/apple/pkl/commit/5db648fc181c2c6c83147fb993b3b64e268a164d) Improve handling of errors when analysis fails - [`aa145bc`](https://github.com/apple/pkl/commit/aa145bcda07e23b2af02afc199e43e5ea684e045) Address review feedback - [`7738181`](https://github.com/apple/pkl/commit/7738181177dd6e34694a1c09632553ec8c26607c) Run spotless apply ### 📊 Changes **9 files changed** (+127 additions, -57 deletions) <details> <summary>View changed files</summary> 📝 `pkl-core/src/main/java/org/pkl/core/Analyzer.java` (+1 -3) 📝 `pkl-core/src/main/java/org/pkl/core/runtime/VmImportAnalyzer.java` (+84 -47) 📝 `pkl-core/src/main/java/org/pkl/core/stdlib/analyze/AnalyzeNodes.java` (+2 -7) ➕ `pkl-core/src/test/files/LanguageSnippetTests/input-helper/analyze/cannotFindModule.pkl` (+1 -0) ➕ `pkl-core/src/test/files/LanguageSnippetTests/input-helper/analyze/invalidGlob.pkl` (+1 -0) ➕ `pkl-core/src/test/files/LanguageSnippetTests/input/errors/analyzeImportsCannotFindModule.pkl` (+5 -0) ➕ `pkl-core/src/test/files/LanguageSnippetTests/input/errors/analyzeImportsInvalidGlob.pkl` (+5 -0) ➕ `pkl-core/src/test/files/LanguageSnippetTests/output/errors/analyzeImportsCannotFindModule.err` (+14 -0) ➕ `pkl-core/src/test/files/LanguageSnippetTests/output/errors/analyzeImportsInvalidGlob.err` (+14 -0) </details> ### 📄 Description Modules that cannot be loaded for one reason or another will now include the offending import as part of the stack trace, with a clear error message. Before: ``` –– Pkl Error –– None (cause has no message) x | res = analyze.importGraph(Set(reflect.Module(cannotFindModule).uri)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` After: ``` –– Pkl Error –– Cannot find module `bogusModule.pkl`. x | import "bogusModule.pkl" ^^^^^^^^^^^^^^^^^ at pkl.analyze#importGraph (file:///$snippetsDir/input-helper/analyze/cannotFindModule.pkl) x | res = analyze.importGraph(Set(reflect.Module(cannotFindModule).uri)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` Closes https://github.com/apple/pkl/pull/949 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 01:27:02 +01:00
adam closed this issue 2025-12-30 01:27:02 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#823