diff --git a/public/java/src/org/broadinstitute/sting/commandline/CommandLineProgram.java b/public/java/src/org/broadinstitute/sting/commandline/CommandLineProgram.java index 9e1be5bca..976889613 100644 --- a/public/java/src/org/broadinstitute/sting/commandline/CommandLineProgram.java +++ b/public/java/src/org/broadinstitute/sting/commandline/CommandLineProgram.java @@ -369,9 +369,9 @@ public abstract class CommandLineProgram { System.exit(1); } - public static void exitSystemWithSamError(final Exception e) { - if ( e.getMessage() == null ) - throw new ReviewedStingException("SamException found with no message!", e); + public static void exitSystemWithSamError(final Throwable t) { + if ( t.getMessage() == null ) + throw new ReviewedStingException("SamException found with no message!", t); errorPrintf("------------------------------------------------------------------------------------------%n"); errorPrintf("A BAM ERROR has occurred (version %s): %n", CommandLineGATK.getVersionNumber()); @@ -383,7 +383,7 @@ public abstract class CommandLineProgram { errorPrintf("Also, please ensure that your BAM index is not corrupted: delete the current one and regenerate it with 'samtools index'%n"); printDocumentationReference(); errorPrintf("%n"); - errorPrintf("MESSAGE: %s%n", e.getMessage().trim()); + errorPrintf("MESSAGE: %s%n", t.getMessage().trim()); errorPrintf("------------------------------------------------------------------------------------------%n"); System.exit(1); } diff --git a/public/java/src/org/broadinstitute/sting/gatk/CommandLineGATK.java b/public/java/src/org/broadinstitute/sting/gatk/CommandLineGATK.java index 70c6bc734..bc4c181be 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/CommandLineGATK.java +++ b/public/java/src/org/broadinstitute/sting/gatk/CommandLineGATK.java @@ -101,20 +101,28 @@ public class CommandLineGATK extends CommandLineExecutable { // TODO: Should Picard exceptions be, in general, UserExceptions or ReviewedStingExceptions? exitSystemWithError(e); } catch (SAMException e) { - checkForTooManyOpenFilesProblem(e.getMessage()); + checkForMaskedUserErrors(e); exitSystemWithSamError(e); } catch (OutOfMemoryError e) { exitSystemWithUserError(new UserException.NotEnoughMemory()); } catch (Throwable t) { - checkForTooManyOpenFilesProblem(t.getMessage()); + checkForMaskedUserErrors(t); exitSystemWithError(t); } } - private static void checkForTooManyOpenFilesProblem(String message) { - // Special case the "Too many open files" error because it's a common User Error for which we know what to do - if ( message != null && message.indexOf("Too many open files") != -1 ) + private static void checkForMaskedUserErrors(final Throwable t) { + final String message = t.getMessage(); + if ( message == null ) + return; + + // we know what to do about the common "Too many open files" error + if ( message.indexOf("Too many open files") != -1 ) exitSystemWithUserError(new UserException.TooManyOpenFiles()); + + // Malformed BAM looks like a SAM file + if ( message.indexOf("Cannot use index file with textual SAM file") != -1 ) + exitSystemWithSamError(t); } /**