dfmt
dfmt copied to clipboard
Non-zero exit code on error
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
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.
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