-
Notifications
You must be signed in to change notification settings - Fork 576
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
Propagate non-zero Picard tool exit codes. #4437
Changes from 1 commit
3cb9bb1
90e89d9
a3497bd
4bf6530
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
import htsjdk.samtools.util.StringUtil; | ||
import org.broadinstitute.hellbender.cmdline.CommandLineProgram; | ||
import org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions; | ||
import org.broadinstitute.hellbender.exceptions.PicardNonZeroExitException; | ||
import org.broadinstitute.hellbender.exceptions.UserException; | ||
import org.broadinstitute.hellbender.utils.ClassUtils; | ||
import org.broadinstitute.hellbender.utils.runtime.RuntimeUtils; | ||
|
@@ -201,6 +202,10 @@ protected final void mainEntry(final String[] args) { | |
} | ||
handleUserException(e); | ||
System.exit(COMMANDLINE_EXCEPTION_EXIT_VALUE); | ||
} catch (PicardNonZeroExitException e) { | ||
// a Picard tool returned a non-zero exit code | ||
handleResult(e.getToolReturnCode()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why should the result be printed on the command line? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did that to retain the Picard return code, which may be different than the one returned by GATK. We could make it return the actual Picard value directly, but that might be misleading since those values are not drawn from the same space as the current GATK values. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I though that the idea was to exit with the same return code as Picard, not to print out the Picard return code and then exit with a different one. For example, for That's why I put this comment, but if that was not the idea it's fine too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first order concern was to make sure that failure resulted in a non-zero return code. Otherwise, as mentioned above, the values themselves are hard not that reliable - I don't think Picard is even self-consistent, since ValidateSamFile returns 1 if there are validation warnings or if there is a command line parsing error. |
||
System.exit(ANY_OTHER_EXCEPTION_EXIT_VALUE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be better to have a separate exit status code for the case where a Picard tool exits with non-0, so that clients will know to check the log to get the underlying Picard exit code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
} catch (final UserException e){ | ||
handleUserException(e); | ||
System.exit(USER_EXCEPTION_EXIT_VALUE); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.broadinstitute.hellbender.exceptions; | ||
|
||
import org.broadinstitute.hellbender.utils.Utils; | ||
|
||
/** | ||
* Exception used to propagate non-zero return values from Picard tools. | ||
*/ | ||
public class PicardNonZeroExitException extends RuntimeException { | ||
private static final long serialVersionUID = 0L; | ||
private final int picardToolReturnCode; | ||
|
||
/** | ||
* | ||
* @param picardToolReturnCode the non-zero return code returned from the Picard tool | ||
*/ | ||
public PicardNonZeroExitException(final int picardToolReturnCode) { | ||
this.picardToolReturnCode = picardToolReturnCode; | ||
Utils.validateArg(picardToolReturnCode != 0, "Return code must be non-zero"); | ||
} | ||
|
||
public int getToolReturnCode() { return picardToolReturnCode; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. javadoc for this method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,4 +94,17 @@ public void testMainErrorWithoutStackTrace() { | |
System.setSecurityManager(backup); | ||
} | ||
} | ||
@Test(singleThreaded = true) | ||
public void testNonZeroPicardReturnValue() { | ||
final SecurityManager backup = System.getSecurityManager(); | ||
try { | ||
System.setSecurityManager(new ThrowOnExitSecurityManager()); | ||
new Main().mainEntry(new String[]{"ExtractSequences"}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check the return value of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't do that directly, because mainEntry never returns in this case; it exits when it detects the failure code. The custom security manager class intercepts the exit and throws the ExitNotAllowedException, which includes the code, which is asserted in the catch clause. |
||
} catch (ExitNotAllowedException e) { | ||
Assert.assertNotEquals(e.status, 0); | ||
} finally { | ||
System.setSecurityManager(backup); | ||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final