Pretty printing error messages #3027
Merged
+3,414
−1,209
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is still a draft, posting for opinions and comments.
This PR changes the error message type from a
string
into alist Pprint.document
. This allows to present better messages to the user, as we can retain the indentation of printed terms, even with line breaks and the like. We can also wrap text to a comfortable line length.I used a list to allow for several sections within a single error. We usually prepend some context to an error, or append some hint or range, and using just strings that gets pretty messy. Using a list allows to do that very easily by just adding a doc to the chosen end of the list. I copied a bit of the style from GHC.
Here's a small example of the difference, before (ignore the

>>Got issues
markers):After:

Before with

--query_stats
and--error_contexts
(just the tail):After with

--query_stats
and--error_contexts
(just the tail):See ae1f869 for a complete diff of the error message expected output.
When in VSCode/Emacs, the messages are rendered before passing them to the editor. Here's an example from Pulse:

The
Error <unknown>
is a Pulse problem I think, in that it doesn't set the error number. I chose to display<unknown>
in that case. Also note that I am displaying the "header" there since I didn't see the error number anywhere in VScode, and I think ideally the error should look exactly the same in both cases. But Emacs does display it, so we need to make a choice.Pending:
Error
/Warning
part of the message, or to the header or whatever. Should we do that? The whole thing being red may be a bit too much, and also prevents coloring a part of the message if needed (e.g. if we want to highlight a difference, something that I want to do).mkmsg : string -> error_message
by default, so they get wrapping automatically. This is sometimes undesirable as it will kill the formatting of aterm_to_string
inside the error, so we should change them before merging.FStar.Issue.fsti
inulib/
. Currently userspace can only use strings, so formatting is lost.