-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better reporting on parsing error caused by idempotency problems #530
Comments
v0.1.0❯ echo 'let id = if true then Fun.id else function x -> x' | cargo run -- --language ocaml
let id = if true then Fun.id else function x -> x v0.2.0 - v0.2.2❯ echo 'let id = if true then Fun.id else function x -> x' | cargo run -- --language ocaml -s
let id = if true then Fun.id else functionx -> x
❯ echo 'let id = if true then Fun.id else function x -> x' | cargo run -- --language ocaml
[2023-06-26T11:50:01Z ERROR topiary] Parsing error between line 1, column 1 and line 1, column 49 v0.2.3 - master❯ echo 'let id = if true then Fun.id else function x -> x' | cargo run -- --language ocaml -s
let id = if true then Fun.id else functionx -> x
❯ echo 'let id = if true then Fun.id else function x -> x' | cargo run -- --language ocaml
[2023-06-26T11:43:04Z ERROR topiary] Parsing error between line 1, column 46 and line 1, column 47 I'd really like to test how idempotency errors got reported pre v0.2.0, but I don't know how to reproduce that. |
Me too. I tried but didn't manage. |
I can force it by adding this: (
(let_binding) @append_delimiter
(#delimiter! ".")
) Then I get: v0.1.0❯ echo 'let id = if true then Fun.id else function x -> x' | cargo run -- --language ocaml
[2023-06-26T11:59:38Z ERROR topiary] Failed idempotence check
[2023-06-26T11:59:38Z ERROR topiary] Diff < left / right > :
<let id = if true then Fun.id else function x -> x.
>let id = if true then Fun.id else function x -> x. .
[2023-06-26T11:59:38Z ERROR topiary] The formatter did not produce the same result when invoked twice (idempotence check).
It would be helpful if you logged this error at https://github.com/tweag/topiary/issues/new?assignees=&labels=type%3A+bug&template=bug_report.md Newer versions behave as above. So the idempotency reporting has definitely regressed. |
This is not an idempotency issue caused by an unparseable production in the first pass though, is it? |
Actually, no, it hasn't regressed. The behaviour is by design. Even the latest version of Topiary catches an idempotency error like this: ❯ echo 'let id = if true then Fun.id else Fun.id' | cargo run -- --language ocaml
[2023-06-26T12:24:36Z ERROR topiary] Failed idempotence check
[2023-06-26T12:24:36Z ERROR topiary] Diff < left / right > :
<let id = if true then Fun.id else Fun.idX
>let id = if true then Fun.id else Fun.idXX
[2023-06-26T12:24:36Z ERROR topiary] The formatter did not produce the same result when invoked twice (idempotence check).
It would be helpful if you logged this error at https://github.com/tweag/topiary/issues/new?assignees=&labels=type%3A+bug&template=bug_report.md But the issue you are running into isn't regarded as an idempotency error, but a formatting error: // If topiary ran smoothly on its own output,
// but produced a different output, it is a Idempotence error.
FormatterError::Idempotence => Err(FormatterError::Idempotence),
// On the other hand, if it failed to run on its output,
// it means that when formatting the code, topiary somehow broke it.
// Hence it is a formatting error.
_ => Err(FormatterError::Formatting(Box::new(err))), Whether this is good or bad is open to debate. |
I'm not particularly attached to reporting it as an idempotency error. I do however think that it is bad to report it as a parsing error without telling the user that it is not their fault and that they should open an issue. |
How about this?
|
Looks amazing to me! |
Is your feature request related to a problem? Please describe.
Consider the following piece of code:
It is valid OCaml code. However, running latest Topiary reports a parsing error:
The error comes in fact from the fact that the first pass of Topiary produces an invalid file (cf #529) and the second pass then fails parsing it. In this case, the location is somewhat correct but in other situations the line numbers might be completely wrong (if previous lines were affected by the first pass of formatting), leaving a user clueless.
Describe the solution you'd like
I want an error message that explains that it is an idempotency error and that it is not the user's fault and that it should be reported.
Additional context
If I am not mistaken, v0.1.0 used to do this?
The text was updated successfully, but these errors were encountered: