diff --git a/dhall/src/semantics/resolve/resolve.rs b/dhall/src/semantics/resolve/resolve.rs index 614ea22f..68b899c6 100644 --- a/dhall/src/semantics/resolve/resolve.rs +++ b/dhall/src/semantics/resolve/resolve.rs @@ -411,9 +411,17 @@ fn resolve_with_env( // Resolve this import, making sure that recursive imports don't cycle back to the // current one. - let typed = env.with_cycle_detection(location.clone(), |env| { + let res = env.with_cycle_detection(location.clone(), |env| { resolve_one_import(env, &import, location.clone(), span.clone()) - })?; + }); + let typed = match res { + Ok(typed) => typed, + Err(e) => mkerr( + ErrorBuilder::new("error") + .span_err(span.clone(), e.to_string()) + .format(), + )?, + }; // Add the resolved import to the caches check_hash(&import, &typed, span)?; diff --git a/dhall/tests/import/failure/alternativeEnv.txt b/dhall/tests/import/failure/alternativeEnv.txt index 482b68ca..bb862c33 100644 --- a/dhall/tests/import/failure/alternativeEnv.txt +++ b/dhall/tests/import/failure/alternativeEnv.txt @@ -1 +1,6 @@ -MissingEnvVar +Type error: error: error + --> :1:45 + | +1 | env:UNSET1 as Text ? env:UNSET2 ? missing ? env:UNSET3 + | ^^^^^^^^^^ MissingEnvVar + | diff --git a/dhall/tests/import/failure/alternativeEnvMissing.txt b/dhall/tests/import/failure/alternativeEnvMissing.txt index 4666330a..1f264628 100644 --- a/dhall/tests/import/failure/alternativeEnvMissing.txt +++ b/dhall/tests/import/failure/alternativeEnvMissing.txt @@ -1 +1,6 @@ -Missing +Type error: error: error + --> :1:13 + | +1 | env:UNSET ? missing + | ^^^^^^^ Missing + | diff --git a/dhall/tests/import/failure/cycle.txt b/dhall/tests/import/failure/cycle.txt index f5a1abff..899484bc 100644 --- a/dhall/tests/import/failure/cycle.txt +++ b/dhall/tests/import/failure/cycle.txt @@ -1 +1,16 @@ -ImportCycle([Local("./dhall-lang/tests/import/data/cycle.dhall"), Local("./dhall-lang/tests/import/failure/cycle.dhall")], Local("./dhall-lang/tests/import/data/cycle.dhall")) +Type error: error: error + --> :1:1 + | +1 | ../data/cycle.dhall + | ^^^^^^^^^^^^^^^^^^^ Type error: error: error + --> :1:1 + | +1 | ../failure/cycle.dhall + | ^^^^^^^^^^^^^^^^^^^^^^ Type error: error: error + --> :1:1 + | +1 | ../data/cycle.dhall + | ^^^^^^^^^^^^^^^^^^^ ImportCycle([Local("./dhall-lang/tests/import/data/cycle.dhall"), Local("./dhall-lang/tests/import/failure/cycle.dhall")], Local("./dhall-lang/tests/import/data/cycle.dhall")) + | + | + | diff --git a/dhall/tests/import/failure/importBoundary.txt b/dhall/tests/import/failure/importBoundary.txt index 56810e26..6ddb3268 100644 --- a/dhall/tests/import/failure/importBoundary.txt +++ b/dhall/tests/import/failure/importBoundary.txt @@ -1,7 +1,12 @@ -Type error: error: unbound variable `x` +Type error: error: error + --> :1:15 + | +1 | \(x: Bool) -> ../data/importBoundary.dhall + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Type error: error: unbound variable `x` --> :1:1 | ... 3 | x | ^ not found in this scope | + | diff --git a/dhall/tests/import/failure/missing.txt b/dhall/tests/import/failure/missing.txt index 4666330a..a15e9e00 100644 --- a/dhall/tests/import/failure/missing.txt +++ b/dhall/tests/import/failure/missing.txt @@ -1 +1,6 @@ -Missing +Type error: error: error + --> :1:1 + | +1 | missing + | ^^^^^^^ Missing + | diff --git a/dhall/tests/import/failure/referentiallyInsane.txt b/dhall/tests/import/failure/referentiallyInsane.txt index 9b5fe914..1c6852a6 100644 --- a/dhall/tests/import/failure/referentiallyInsane.txt +++ b/dhall/tests/import/failure/referentiallyInsane.txt @@ -1 +1,12 @@ -SanityCheck +Type error: error: error + --> :6:1 + | + 1 | {- The following remote import attempts to import an environment variable, which + 2 | must be disallowed by the referential sanity check + 3 | + 4 | One reason for doing this is to protect against remote imports exfiltrating +... +12 | -} +13 | https://raw.githubusercontent.com/dhall-lang/dhall-lang/master/tests/import/data/referentiallyOpaque.dhall + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SanityCheck + | diff --git a/dhall/tests/import/failure/unit/EnvUnset.txt b/dhall/tests/import/failure/unit/EnvUnset.txt index 482b68ca..12a8953f 100644 --- a/dhall/tests/import/failure/unit/EnvUnset.txt +++ b/dhall/tests/import/failure/unit/EnvUnset.txt @@ -1 +1,6 @@ -MissingEnvVar +Type error: error: error + --> :1:1 + | +1 | env:DHALL_TEST_UNSET + | ^^^^^^^^^^^^^^^^^^^^ MissingEnvVar + | diff --git a/dhall/tests/import/failure/unit/EnvUnsetAsText.txt b/dhall/tests/import/failure/unit/EnvUnsetAsText.txt index 482b68ca..65715600 100644 --- a/dhall/tests/import/failure/unit/EnvUnsetAsText.txt +++ b/dhall/tests/import/failure/unit/EnvUnsetAsText.txt @@ -1 +1,6 @@ -MissingEnvVar +Type error: error: error + --> :1:1 + | +1 | env:DHALL_TEST_UNSET as Text + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ MissingEnvVar + | diff --git a/dhall/tests/import/failure/unit/FileMissing.dhall b/dhall/tests/import/failure/unit/FileMissing.dhall new file mode 100644 index 00000000..cba1bccb --- /dev/null +++ b/dhall/tests/import/failure/unit/FileMissing.dhall @@ -0,0 +1 @@ +./not-a-file.dhall diff --git a/dhall/tests/import/failure/unit/FileMissing.txt b/dhall/tests/import/failure/unit/FileMissing.txt new file mode 100644 index 00000000..351909da --- /dev/null +++ b/dhall/tests/import/failure/unit/FileMissing.txt @@ -0,0 +1,6 @@ +Type error: error: error + --> :1:1 + | +1 | ./not-a-file.dhall + | ^^^^^^^^^^^^^^^^^^ No such file or directory (os error 2) + |