From 1e2d323a7c5b554f69902987b57c9d47d57e7eea Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Thu, 6 Oct 2022 17:22:17 +0300 Subject: feat(tvix/eval): fancy-format parse errors returned by rnix 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 Autosubmit: tazjin Tested-by: BuildkiteCI --- tvix/eval/src/builtins/impure.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tvix/eval/src/builtins/impure.rs') diff --git a/tvix/eval/src/builtins/impure.rs b/tvix/eval/src/builtins/impure.rs index 348963e893..a1bcc602dc 100644 --- a/tvix/eval/src/builtins/impure.rs +++ b/tvix/eval/src/builtins/impure.rs @@ -63,15 +63,16 @@ pub fn builtins_import( let parsed = rnix::ast::Root::parse(&contents); let errors = parsed.errors(); + let file = source.add_file(path.to_string_lossy().to_string(), contents); + if !errors.is_empty() { return Err(ErrorKind::ImportParseError { path, + file, errors: errors.to_vec(), }); } - let file = source.add_file(path.to_string_lossy().to_string(), contents); - let result = crate::compile( &parsed.tree().expr().unwrap(), Some(path.clone()), -- cgit 1.4.1