Skip to content

Commit

Permalink
Fix #1914
Browse files Browse the repository at this point in the history
Error code of dune format should be non zero when it fails

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
  • Loading branch information
rgrinberg committed Mar 7, 2019
1 parent f595dcb commit c7ea149
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ correctly erased by ^K. (#1912, @aalekseyev)
- Fix generation of `.merlin` files on Windows. `\` characters needed
to be escaped (#1869, @mlasson)

- Fix 0 error code when `$ dune format-dune-file` fails. (#1915, fix #1914,
@rgrinberg)

1.7.3 (unreleased)
------------------

Expand Down
5 changes: 3 additions & 2 deletions src/format_dune_lang.ml
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ let pp_top_sexps =
let format_file ~input =
match parse_file input with
| exception Dune_lang.Parse_error e ->
Printf.printf
Printf.eprintf
"Parse error: %s\n"
(Dune_lang.Parse_error.message e)
(Dune_lang.Parse_error.message e);
exit 1
| OCaml_syntax loc ->
Errors.warn loc "OCaml syntax is not supported, skipping."
| Sexps sexps ->
Expand Down
7 changes: 7 additions & 0 deletions test/blackbox-tests/test-cases/format-dune-file/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Parse errors are displayed:

$ echo '(' | dune format-dune-file
Parse error: unclosed parenthesis at end of input
[1]

When a list is indented, there is no extra space at the end.

Expand Down Expand Up @@ -153,3 +154,9 @@ Files in OCaml syntax are ignored with a warning.
1 | (* -*- tuareg -*- *)
^^^^^^^^^^^^^^^^^^^^
Warning: OCaml syntax is not supported, skipping.
Non 0 error code:
$ echo "(" | dune format ; echo $?
Parse error: unclosed parenthesis at end of input
1

0 comments on commit c7ea149

Please sign in to comment.