-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can we improve import errors? #561
Comments
@joneshf: Yeah, this should be doable. The only reason that the dhall-haskell/src/Dhall/Import.hs Line 596 in b5c005e
... and that function is only provided an annotateEmbed :: Expr s a -> Expr s (Maybe s, a) ... which in the common case would specialize to: annotateEmbed :: Expr Src Import -> Expr Src (Maybe Src, Import) ... and then changing exprFromImport :: Maybe Src -> Import -> StateT (Status IO) IO (Expr Src Import) ... and then we'd have the source information we needed to annotate where the missing file import came from. There's also no reason why we can't add support for the Line 542 in b5c005e
... to catch I can also do these changes for you, but you're welcome to take a stab at it before I get to it if you want. |
I haven't forgotten about this issue 🙂 (though I did forget to respond). Thanks for the explanation! I think I'll probably hop on it the next time I get hit by it. |
Ping. I’m trying to write a flycheck plugin for emacs, so I’d like to show the user all files that can’t be imported. One intermediate solution would be to try import, catch import errors and then iterate over the AST to try and resolve each import separately. |
Related to #561 This adds source position information to missing imports Before: ``` $ dhall <<< './foo' ↳ ./foo Error: Missing file …/foo ``` After: ``` $ dhall <<< './foo' ↳ ./foo Error: Missing file …/foo (stdin):1:1 ```
First change to add source locations to missing imports is up here: #812 |
Related to #561 This adds source position information to missing imports Before: ``` $ dhall <<< './foo' ↳ ./foo Error: Missing file …/foo ``` After: ``` $ dhall <<< './foo' ↳ ./foo Error: Missing file …/foo (stdin):1:1 ```
@Profpatsch: I don't plan to get to import error messages that list all failed imports, for two main reasons:
If somebody adds support for that I'll accept the patch, though |
@joneshf: So I've gotten about as far as I think I will get on this at the moment (once #815 is merged) Additional improvements will require me to overhaul Dhall's exception system because it's a bit of a mess at this point, which is the root cause of some of the issues you described, such as:
|
Very valid.
The multiple error messages changes is gonna block on that, too. For
Though to be honest the time spent with import errors is minimal in most cases, so it’s a heavy investment for a pretty small gain. If the exceptions were to be replaced by return values the change should be trivial though. |
Sounds good. Should we close this issue in exchange for whatever exception overhaul will come out or leave it open to track that this pain point still exists? |
@joneshf: It's fine to leave this issue open for now |
Updating It’s just not possible to correctly wrap dhall at the moment and being sure that errors are handled exhaustively. Or even get much information out of them (e.g. for inline errors that should appear in the file which threw an import error). I would very much appreciate if the switch away from exceptions towards structured errors (via |
Also errors like |
@Profpatsch PRs to improve the situation would be very welcome! :) |
I’m afraid I don’t have time to deep-dive at the moment (it’s a rather fundamental change of the main functions), I just wanted to bump the topic to mark interest. |
I notice that the pretty-printed error message contains an import chain, though I’m not sure where it gets it from. It’s not in the errors that are thrown by
|
For reference, this is how I catch errors at the moment: Note that this list has to be kept in sync with the actual (open) error list on every update (no type errors), otherwise the checker randomly crashes. And I really don’t want to catch all exceptions, because that’s a big no-go in the presence of signals and async errors (see the relevant section in |
Could a first step be to have a single exception type? data ImportException
= ImportResolutionDisabled Dhall.Import.ImportResolutionDisabled
| PrettyHttpException Dhall.Import.PrettyHttpException
... You ought to be able to exhaustively check the exceptions, and it ought to be less invasive than both changing the types and also changing the error handling mechanism. Would that work? |
It would solve the problem of not being forced to be exhaustive, yes, but not the problem of having no good error positions for most of these errors. Maybe I’m missing a way to read them from some evaluation context. |
I'm doing some file renames for dhall-bhat, and the error message for missing imports can get a little confusing. For example:
The error message does give all of the information necessary to figure out the problem, but there's some hard things about it:
./List/traversable
, but the last line–that says what the error is–doesn't mention./List/traversable
. You have to parse the import chain to find the second to last import to know where the error occurred.--explain
flag. For the most part, when I get stuck on something, I can add the--explain
flag, and get unstuck. The examples and explanations are top-notch.Is there some way we can improve these issues? Do we have enough information to add locations and whatnot to the error? I'm happy to submit a PR to help out.
The text was updated successfully, but these errors were encountered: