Skip to content

Return a non-zero exit code upon error #882

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

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ static int main(PrintWriter out, PrintWriter err, String... args) {
return formatter.format(args);
} catch (UsageException e) {
err.print(e.getMessage());
return 0;
// We return exit code 2 to differentiate usage issues from code formatting issues.
return 2;
} finally {
err.flush();
out.flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void testUsageOutputAfterLoadingViaToolName() {

int result = format.run(new PrintWriter(out, true), new PrintWriter(err, true), "--help");

assertThat(result).isEqualTo(0);
assertThat(result).isEqualTo(2);

String usage = err.toString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void testMain() throws Exception {
process.waitFor();
String err = new String(ByteStreams.toByteArray(process.getErrorStream()), UTF_8);
assertThat(err).contains("Usage: google-java-format");
assertThat(process.exitValue()).isEqualTo(0);
assertThat(process.exitValue()).isEqualTo(2);
}

// end to end javadoc formatting test
Expand Down