dhall-rust icon indicating copy to clipboard operation
dhall-rust copied to clipboard

Tracking issue for great error messages

Open Nadrieril opened this issue 5 years ago • 8 comments

Nadrieril avatar Mar 30 '19 18:03 Nadrieril

I'd like to follow the style of Rust error messages, because they rock. Note to self: have a look at https://github.com/rust-lang/rust/blob/master/src/librustc_errors/lib.rs

Nadrieril avatar Sep 20 '19 20:09 Nadrieril

First step done ! https://github.com/Nadrieril/dhall-rust/pull/114

Nadrieril avatar Nov 11 '19 18:11 Nadrieril

Next step: https://github.com/Nadrieril/dhall-rust/issues/116

Nadrieril avatar Nov 11 '19 18:11 Nadrieril

Most of the groundwork is done, now there's mostly a need of writing nice error messages.

Nadrieril avatar Feb 06 '20 16:02 Nadrieril

The state of error messages can be seen in the .txt files in dhall/tests/.../failure/.... For example: https://github.com/Nadrieril/dhall-rust/blob/2ca97e97f1718141d826a78ab3da8197b2d55c69/dhall/tests/type-inference/failure/unit/AssertTriviallyFalse.txt#L1-L6 This is not amazing yet, but at least it points to the correct location in the source file. Some errors fail to do even that, either because of some complicated Span story or because we don't even try (see e.g. import errors). The goal would be better error messages like this one: https://github.com/Nadrieril/dhall-rust/blob/2ca97e97f1718141d826a78ab3da8197b2d55c69/dhall/tests/type-inference/failure/unit/FunctionApplicationArgumentNotMatch.txt#L1-L9

Nadrieril avatar Mar 05 '20 16:03 Nadrieril

Errors are not pretty printed in test outputs. It seems like it is attempting to use the Debug version instead. For example this is the output when I tried to create a test case for the issue in #173

---- test_rename_all_camel_case stdout ----
thread 'test_rename_all_camel_case' panicked at 'called `Result::unwrap()` on an `Err` value: Error(Dhall(Error { kind: Typecheck(TypeError { message: Custom("error: annot mismatch: { function : Text, mergeVariant : Optional Text, postVariant : Optional Text, preVariant : Optional Text } != { function : Text, `merge_variant` : Optional Text, `post_variant` : Optional Text, `pre_variant` : Optional Text }\n --> <current file>:2:1\n  |\n... |\n6 | |     }\n  | |______^ annot mismatch: { function : Text, mergeVariant : Optional Text, postVariant : Optional Text, preVariant : Optional Text } != { function : Text, `merge_variant` : Optional Text, `post_variant` : Optional Text, `pre_variant` : Optional Text }\n  |") }) }))', serde_dhall/tests/rename.rs:33:10

rushsteve1 avatar Sep 13 '20 13:09 rushsteve1

You get this output because you used .unwrap() in your test case. .unwrap() will indeed use the Debug impl to display the values, which is not nice here. The way I would do it here is just define a parse function that extracts the error and manually prints is with its Display impl. Something like

fn parse<T: FromDhall + StaticType>(s: &str) -> T {
	match from_str(s).static_type_annotation().parse() {
		Ok(x) => x,
		Err(e) => panic!("{}", e),
	}
}

and then use parse::<Transform>(test_str). It's a bit annoying but the Debug impl is often useful for tricky cases so I want to keep it around.

Nadrieril avatar Sep 14 '20 21:09 Nadrieril

I created a relevant issue: #228

alefminus avatar May 17 '22 07:05 alefminus