Giter Club home page Giter Club logo

Comments (8)

Nadrieril avatar Nadrieril commented on June 15, 2024 1

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

from dhall-rust.

Nadrieril avatar Nadrieril commented on June 15, 2024

First step done ! #114

from dhall-rust.

Nadrieril avatar Nadrieril commented on June 15, 2024

Next step: #116

from dhall-rust.

Nadrieril avatar Nadrieril commented on June 15, 2024

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

from dhall-rust.

Nadrieril avatar Nadrieril commented on June 15, 2024

The state of error messages can be seen in the .txt files in dhall/tests/.../failure/.... For example:

Type error: error: AssertMismatch
--> <current file>:1:0
|
1 | assert : 1 === 2
| ^^^^^^^^^^^^^^^^ AssertMismatch
|

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:
Type error: error: wrong type of function argument
--> <current file>:1:1
|
1 | (λ(_ : Natural) → _) True
| ^^^^^^^^^^^^^^^^^^ this expects an argument of type: Natural
| ^^^^ but this has type: Bool
|
= note: expected type `Natural`
found type `Bool`

from dhall-rust.

rushsteve1 avatar rushsteve1 commented on June 15, 2024

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

from dhall-rust.

Nadrieril avatar Nadrieril commented on June 15, 2024

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.

from dhall-rust.

alefminus avatar alefminus commented on June 15, 2024

I created a relevant issue: #228

from dhall-rust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.