diff options
author | Vincent Ambo <mail@tazj.in> | 2022-10-06T14·22+0300 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2022-10-08T17·27+0000 |
commit | 1e2d323a7c5b554f69902987b57c9d47d57e7eea (patch) | |
tree | f75871cc46781197250b2dce238171b4b297c979 /tvix/eval/src/eval.rs | |
parent | 70427fd93470536c36b2fa8a6c9446f746dcfbec (diff) |
feat(tvix/eval): fancy-format parse errors returned by rnix r/5063
This change is quite verbose, so a little bit of explaining: 1. To correctly format parse errors, errors must be able to return more than one annotated span (the parser returns a list of errors for each span). To accomplish this, the structure of how the `Diagnostic` struct which formats an error is constructed has changed to delegate the creation of the `SpanLabel` vector to the kind of error. 2. The rnix structures don't have human-readable output formats by default, so some verbose methods for formatting them in human-readable ways have been added in the errors module. We might want to move these out into a submodule. 3. In many cases, the errors returned by rnix are a bit strange - so while we format them with all information that is easily available they may look weird or not necessarily help users. Consider this CL only a first step in the right direction. Change-Id: Ie7dd74751af9e7ecb35d751f8b087aae5ae6e2e8 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6871 Reviewed-by: sterni <sternenseemann@systemli.org> Autosubmit: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/eval.rs')
-rw-r--r-- | tvix/eval/src/eval.rs | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/tvix/eval/src/eval.rs b/tvix/eval/src/eval.rs index 5af5f9d7588e..e2495b69cdb0 100644 --- a/tvix/eval/src/eval.rs +++ b/tvix/eval/src/eval.rs @@ -39,13 +39,12 @@ pub fn interpret(code: &str, location: Option<PathBuf>, options: Options) -> Eva let errors = parsed.errors(); if !errors.is_empty() { - for err in errors { - eprintln!("parse error: {}", err); - } - return Err(Error { + let err = Error { kind: ErrorKind::ParseErrors(errors.to_vec()), span: file.span, - }); + }; + err.fancy_format_stderr(&source); + return Err(err); } // If we've reached this point, there are no errors. |