Improve handling of errors when analysis fails (#948)

Modules that cannot be loaded for one reason or another now cause a Pkl Exception,
with the offending import highlighted as part of the stack trace.
This commit is contained in:
Daniel Chao
2025-02-13 14:00:48 -08:00
committed by GitHub
parent 65cf3237b7
commit 1a4f9ee72e
9 changed files with 127 additions and 57 deletions
@@ -0,0 +1 @@
import "bogusModule.pkl"
@@ -0,0 +1 @@
import* ".../**.pkl"
@@ -0,0 +1,5 @@
import "pkl:analyze"
import "pkl:reflect"
import ".../input-helper/analyze/cannotFindModule.pkl"
res = analyze.importGraph(Set(reflect.Module(cannotFindModule).uri))
@@ -0,0 +1,5 @@
import "pkl:analyze"
import "pkl:reflect"
import ".../input-helper/analyze/invalidGlob.pkl"
res = analyze.importGraph(Set(reflect.Module(invalidGlob).uri))
@@ -0,0 +1,14 @@
–– 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))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at analyzeImportsCannotFindModule#res (file:///$snippetsDir/input/errors/analyzeImportsCannotFindModule.pkl)
xxx | text = renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (pkl:base)
@@ -0,0 +1,14 @@
–– Pkl Error ––
Cannot combine glob imports with triple-dot module URIs.
x | import* ".../**.pkl"
^^^^^^^^^^^^^^^^^^^^
at analyzeImportsInvalidGlob#invalidGlob (file:///$snippetsDir/input-helper/analyze/invalidGlob.pkl)
x | res = analyze.importGraph(Set(reflect.Module(invalidGlob).uri))
^^^^^^^^^^^
at analyzeImportsInvalidGlob#res (file:///$snippetsDir/input/errors/analyzeImportsInvalidGlob.pkl)
xxx | text = renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (pkl:base)