@Test public void testBuildSystemException() { String message = "This is an exception"; UserException uex = UserException.systemError(new Exception(new RuntimeException(message))).build(logger); Assert.assertTrue(uex.getOriginalMessage().contains(message)); Assert.assertTrue(uex.getOriginalMessage().contains("RuntimeException")); DrillPBError error = uex.getOrCreatePBError(true); Assert.assertEquals(ErrorType.SYSTEM, error.getErrorType()); }
setErrorType(other.getErrorType());
@Test public void testBuildUserExceptionWithCauseAndMessage() { String messageA = "Test message A"; String messageB = "Test message B"; UserException uex = UserException.dataWriteError(new RuntimeException(messageA)).message(messageB).build(logger); DrillPBError error = uex.getOrCreatePBError(false); // passed message should override the cause message Assert.assertEquals(ErrorType.DATA_WRITE, error.getErrorType()); Assert.assertFalse(error.getMessage().contains(messageA)); // messageA should not be part of the context Assert.assertEquals(messageB, uex.getOriginalMessage()); }
setErrorType(other.getErrorType());
public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.exec.proto.UserBitShared.DrillPBError message) throws java.io.IOException { if(message.hasErrorId()) output.writeString(1, message.getErrorId(), false); if(message.hasEndpoint()) output.writeObject(2, message.getEndpoint(), org.apache.drill.exec.proto.SchemaCoordinationProtos.DrillbitEndpoint.WRITE, false); if(message.hasErrorType()) output.writeEnum(3, message.getErrorType().getNumber(), false); if(message.hasMessage()) output.writeString(4, message.getMessage(), false); if(message.hasException()) output.writeObject(5, message.getException(), org.apache.drill.exec.proto.SchemaUserBitShared.ExceptionWrapper.WRITE, false); for(org.apache.drill.exec.proto.UserBitShared.ParsingError parsingError : message.getParsingErrorList()) output.writeObject(6, parsingError, org.apache.drill.exec.proto.SchemaUserBitShared.ParsingError.WRITE, true); } public boolean isInitialized(org.apache.drill.exec.proto.UserBitShared.DrillPBError message)
public UserRemoteException(DrillPBError error) { super(error.getErrorType(), "Drill Remote Exception", getThrowable(error.getException())); this.error = error; }
public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.exec.proto.UserBitShared.DrillPBError message) throws java.io.IOException { if(message.hasErrorId()) output.writeString(1, message.getErrorId(), false); if(message.hasEndpoint()) output.writeObject(2, message.getEndpoint(), org.apache.drill.exec.proto.SchemaCoordinationProtos.DrillbitEndpoint.WRITE, false); if(message.hasErrorType()) output.writeEnum(3, message.getErrorType().getNumber(), false); if(message.hasMessage()) output.writeString(4, message.getMessage(), false); if(message.hasException()) output.writeObject(5, message.getException(), org.apache.drill.exec.proto.SchemaUserBitShared.ExceptionWrapper.WRITE, false); for(org.apache.drill.exec.proto.UserBitShared.ParsingError parsingError : message.getParsingErrorList()) output.writeObject(6, parsingError, org.apache.drill.exec.proto.SchemaUserBitShared.ParsingError.WRITE, true); } public boolean isInitialized(org.apache.drill.exec.proto.UserBitShared.DrillPBError message)
public UserRemoteException(DrillPBError error) { super(error.getErrorType(), "Drill Remote Exception", getThrowable(error.getException())); this.error = error; }
@Test public void testBuildUserExceptionWithCause() { String message = "Test message"; UserException uex = UserException.dataWriteError(new RuntimeException(message)).build(logger); DrillPBError error = uex.getOrCreatePBError(false); // cause message should be used Assert.assertEquals(ErrorType.DATA_WRITE, error.getErrorType()); Assert.assertEquals(message, uex.getOriginalMessage()); }
@Test public void testBuildUserExceptionWithMessage() { String message = "Test message"; UserException uex = UserException.dataWriteError().message(message).build(logger); DrillPBError error = uex.getOrCreatePBError(false); Assert.assertEquals(ErrorType.DATA_WRITE, error.getErrorType()); Assert.assertEquals(message, uex.getOriginalMessage()); }
@Test public void testBuildUserExceptionWithFormattedMessage() { String format = "This is test #%d"; UserException uex = UserException.connectionError().message(format, 5).build(logger); DrillPBError error = uex.getOrCreatePBError(false); Assert.assertEquals(ErrorType.CONNECTION, error.getErrorType()); Assert.assertEquals(String.format(format, 5), uex.getOriginalMessage()); }