From 8cfb6d563d26abb2fa80124eda2231eb05c7f3e6 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 1 Nov 2020 18:59:01 +0000 Subject: feat: add location to import error messages This is crude but helpful. See #40 --- dhall/src/semantics/resolve/resolve.rs | 12 ++++++++++-- dhall/tests/import/failure/alternativeEnv.txt | 7 ++++++- dhall/tests/import/failure/alternativeEnvMissing.txt | 7 ++++++- dhall/tests/import/failure/cycle.txt | 17 ++++++++++++++++- dhall/tests/import/failure/importBoundary.txt | 7 ++++++- dhall/tests/import/failure/missing.txt | 7 ++++++- dhall/tests/import/failure/referentiallyInsane.txt | 13 ++++++++++++- dhall/tests/import/failure/unit/EnvUnset.txt | 7 ++++++- dhall/tests/import/failure/unit/EnvUnsetAsText.txt | 7 ++++++- dhall/tests/import/failure/unit/FileMissing.dhall | 1 + dhall/tests/import/failure/unit/FileMissing.txt | 6 ++++++ 11 files changed, 81 insertions(+), 10 deletions(-) create mode 100644 dhall/tests/import/failure/unit/FileMissing.dhall create mode 100644 dhall/tests/import/failure/unit/FileMissing.txt (limited to 'dhall') diff --git a/dhall/src/semantics/resolve/resolve.rs b/dhall/src/semantics/resolve/resolve.rs index 614ea22..68b899c 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 482b68c..bb862c3 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 4666330..1f26462 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 f5a1abf..899484b 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 56810e2..6ddb326 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 4666330..a15e9e0 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 9b5fe91..1c6852a 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 482b68c..12a8953 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 482b68c..6571560 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 0000000..cba1bcc --- /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 0000000..351909d --- /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) + | -- cgit v1.2.3