Skip to content

Commit

Permalink
feat: add location to import error messages
Browse files Browse the repository at this point in the history
This is crude but helpful. See #40
  • Loading branch information
Nadrieril committed Nov 1, 2020
1 parent 2ae979a commit 8cfb6d5
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 10 deletions.
12 changes: 10 additions & 2 deletions dhall/src/semantics/resolve/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
7 changes: 6 additions & 1 deletion dhall/tests/import/failure/alternativeEnv.txt
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
MissingEnvVar
Type error: error: error
--> <current file>:1:45
|
1 | env:UNSET1 as Text ? env:UNSET2 ? missing ? env:UNSET3
| ^^^^^^^^^^ MissingEnvVar
|
7 changes: 6 additions & 1 deletion dhall/tests/import/failure/alternativeEnvMissing.txt
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
Missing
Type error: error: error
--> <current file>:1:13
|
1 | env:UNSET ? missing
| ^^^^^^^ Missing
|
17 changes: 16 additions & 1 deletion dhall/tests/import/failure/cycle.txt
Original file line number Diff line number Diff line change
@@ -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
--> <current file>:1:1
|
1 | ../data/cycle.dhall
| ^^^^^^^^^^^^^^^^^^^ Type error: error: error
--> <current file>:1:1
|
1 | ../failure/cycle.dhall
| ^^^^^^^^^^^^^^^^^^^^^^ Type error: error: error
--> <current file>: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"))
|
|
|
7 changes: 6 additions & 1 deletion dhall/tests/import/failure/importBoundary.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
Type error: error: unbound variable `x`
Type error: error: error
--> <current file>:1:15
|
1 | \(x: Bool) -> ../data/importBoundary.dhall
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Type error: error: unbound variable `x`
--> <current file>:1:1
|
...
3 | x
| ^ not found in this scope
|
|
7 changes: 6 additions & 1 deletion dhall/tests/import/failure/missing.txt
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
Missing
Type error: error: error
--> <current file>:1:1
|
1 | missing
| ^^^^^^^ Missing
|
13 changes: 12 additions & 1 deletion dhall/tests/import/failure/referentiallyInsane.txt
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
SanityCheck
Type error: error: error
--> <current file>: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
|
7 changes: 6 additions & 1 deletion dhall/tests/import/failure/unit/EnvUnset.txt
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
MissingEnvVar
Type error: error: error
--> <current file>:1:1
|
1 | env:DHALL_TEST_UNSET
| ^^^^^^^^^^^^^^^^^^^^ MissingEnvVar
|
7 changes: 6 additions & 1 deletion dhall/tests/import/failure/unit/EnvUnsetAsText.txt
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
MissingEnvVar
Type error: error: error
--> <current file>:1:1
|
1 | env:DHALL_TEST_UNSET as Text
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ MissingEnvVar
|
1 change: 1 addition & 0 deletions dhall/tests/import/failure/unit/FileMissing.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./not-a-file.dhall
6 changes: 6 additions & 0 deletions dhall/tests/import/failure/unit/FileMissing.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Type error: error: error
--> <current file>:1:1
|
1 | ./not-a-file.dhall
| ^^^^^^^^^^^^^^^^^^ No such file or directory (os error 2)
|

0 comments on commit 8cfb6d5

Please sign in to comment.