dfmt icon indicating copy to clipboard operation
dfmt copied to clipboard

Non-zero exit code on error

Open lassik opened this issue 7 years ago • 2 comments

Currently the exit code is zero (indicating success) when formatting from stdin to stdout even when there is a syntax error in the code.

$ echo "{" | dfmt; echo "exit code is $?"
stdin(1:1)[error]: declaration expected instead of `{`

{
exit code is 0

I believe it would be better to make it non-zero on error so that editor plugins and batch jobs don't try to use the output from stdout.

I have latest version from Homebrew on MacOS:

$ dfmt --version
0.8.2

lassik avatar Jul 10 '18 09:07 lassik

Aha, I now realize that in case of syntax error you output the invalid code verbatim to stdout anyway. Interesting. I wrote Emacs support for a lot of formatters and I believe this behavior is unique among them. Practically all of them exit non-zero and write nothing to stdout when encountering a syntax error.

lassik avatar Jul 10 '18 10:07 lassik

unparsable code (broken tokens) now emits error code 1, broken syntax still emits error code 0 with partial working output

imo this is a good approach and the general base for this now exists (exit code 1 with no output for complete failure)

see #470

WebFreak001 avatar Mar 09 '20 12:03 WebFreak001