Skip to content
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

have cause of SQLServerException exception at any place where it possible #202

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 5 additions & 5 deletions src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1987,7 +1987,7 @@ final int read(byte[] data,
con.terminate(SQLServerException.ERROR_SOCKET_TIMEOUT, e.getMessage(), e);
}
else {
con.terminate(SQLServerException.DRIVER_ERROR_IO_FAILED, e.getMessage());
con.terminate(SQLServerException.DRIVER_ERROR_IO_FAILED, e.getMessage(), e);
}

return 0; // Keep the compiler happy.
Expand All @@ -2004,7 +2004,7 @@ final void write(byte[] data,
if (logger.isLoggable(Level.FINER))
logger.finer(toString() + " write failed:" + e.getMessage());

con.terminate(SQLServerException.DRIVER_ERROR_IO_FAILED, e.getMessage());
con.terminate(SQLServerException.DRIVER_ERROR_IO_FAILED, e.getMessage(), e);
}
}

Expand All @@ -2016,7 +2016,7 @@ final void flush() throws SQLServerException {
if (logger.isLoggable(Level.FINER))
logger.finer(toString() + " flush failed:" + e.getMessage());

con.terminate(SQLServerException.DRIVER_ERROR_IO_FAILED, e.getMessage());
con.terminate(SQLServerException.DRIVER_ERROR_IO_FAILED, e.getMessage(), e);
}
}

Expand Down Expand Up @@ -3537,7 +3537,7 @@ void writeOffsetDateTimeWithTimezone(OffsetDateTime offsetDateTimeValue,
throw new SQLServerException(SQLServerException.getErrString("R_zoneOffsetError"), null, // SQLState is null as this error is generated in
// the driver
0, // Use 0 instead of DriverError.NOT_SET to use the correct constructor
null);
e);
}
subSecondNanos = offsetDateTimeValue.getNano();

Expand Down Expand Up @@ -3593,7 +3593,7 @@ void writeOffsetTimeWithTimezone(OffsetTime offsetTimeValue,
throw new SQLServerException(SQLServerException.getErrString("R_zoneOffsetError"), null, // SQLState is null as this error is generated in
// the driver
0, // Use 0 instead of DriverError.NOT_SET to use the correct constructor
null);
e);
}
subSecondNanos = offsetTimeValue.getNano();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private static byte[] decryptRSAOAEP(byte[] cipherText,
catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException | BadPaddingException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_CEKDecryptionFailed"));
Object[] msgArgs = {e.getMessage()};
throw new SQLServerException(form.format(msgArgs), null);
throw new SQLServerException(form.format(msgArgs), e);
}

return plainCEK;
Expand All @@ -156,7 +156,7 @@ private static boolean verifyRSASignature(byte[] hash,
catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidCertificateSignature"));
Object[] msgArgs = {masterKeyPath};
throw new SQLServerException(form.format(msgArgs), null);
throw new SQLServerException(form.format(msgArgs), e);
}

return verificationSucess;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static SqlFedAuthToken getSqlFedAuthToken(SqlFedAuthInfo fedAuthInfo,
return fedAuthToken;
}
catch (MalformedURLException | InterruptedException e) {
throw new SQLServerException(e.getMessage(), null);
throw new SQLServerException(e.getMessage(), e);
}
catch (ExecutionException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_ADALExecution"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ else if (null == delimiter) {
}
catch (UnsupportedEncodingException unsupportedEncoding) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_unsupportedEncoding"));
throw new SQLServerException(form.format(new Object[] {encoding}), null, 0, null);
throw new SQLServerException(form.format(new Object[] {encoding}), null, 0, unsupportedEncoding);
}
catch (Exception e) {
throw new SQLServerException(null, e.getMessage(), null, 0, false);
Expand Down Expand Up @@ -523,7 +523,7 @@ public Object[] getRowData() throws SQLServerException {
catch (ArithmeticException ex) {
String value = "'" + data[pair.getKey() - 1] + "'";
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_errorConvertingValue"));
throw new SQLServerException(form.format(new Object[] {value, JDBCType.of(cm.columnType)}), null, 0, null);
throw new SQLServerException(form.format(new Object[] {value, JDBCType.of(cm.columnType)}), null, 0, ex);
}
break;
}
Expand Down Expand Up @@ -648,10 +648,10 @@ else if (dateTimeFormatter != null)
catch (IllegalArgumentException e) {
String value = "'" + data[pair.getKey() - 1] + "'";
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_errorConvertingValue"));
throw new SQLServerException(form.format(new Object[] {value, JDBCType.of(cm.columnType)}), null, 0, null);
throw new SQLServerException(form.format(new Object[] {value, JDBCType.of(cm.columnType)}), null, 0, e);
}
catch (ArrayIndexOutOfBoundsException e) {
throw new SQLServerException(SQLServerException.getErrString("R_BulkCSVDataSchemaMismatch"), null);
throw new SQLServerException(SQLServerException.getErrString("R_BulkCSVDataSchemaMismatch"), e);
}

}
Expand All @@ -665,7 +665,7 @@ public boolean next() throws SQLServerException {
currentLine = fileReader.readLine();
}
catch (IOException e) {
throw new SQLServerException(null, e.getMessage(), null, 0, false);
throw new SQLServerException(e.getMessage(), null, 0, e);
}
return (null != currentLine);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ private void checkForTimeoutException(SQLException e,
connection.rollback();
}

throw new SQLServerException(SQLServerException.getErrString("R_queryTimedOut"), SQLState.STATEMENT_CANCELED, DriverError.NOT_SET, null);
throw new SQLServerException(SQLServerException.getErrString("R_queryTimedOut"), SQLState.STATEMENT_CANCELED, DriverError.NOT_SET, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public byte[] decryptColumnEncryptionKey(String masterKeyPath,
md = MessageDigest.getInstance("SHA-256");
}
catch (NoSuchAlgorithmException e) {
throw new SQLServerException(SQLServerException.getErrString("R_NoSHA256Algorithm"), null);
throw new SQLServerException(SQLServerException.getErrString("R_NoSHA256Algorithm"), e);
}
md.update(hash);
byte dataToVerify[] = md.digest();
Expand Down Expand Up @@ -302,7 +302,7 @@ public byte[] encryptColumnEncryptionKey(String masterKeyPath,
md = MessageDigest.getInstance("SHA-256");
}
catch (NoSuchAlgorithmException e) {
throw new SQLServerException(SQLServerException.getErrString("R_NoSHA256Algorithm"), null);
throw new SQLServerException(SQLServerException.getErrString("R_NoSHA256Algorithm"), e);
}
md.update(dataToHash);
byte dataToSign[] = md.digest();
Expand Down Expand Up @@ -401,7 +401,7 @@ private void ValidateNonEmptyAKVPath(String masterKeyPath) throws SQLServerExcep
catch (URISyntaxException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_AKVURLInvalid"));
Object[] msgArgs = {masterKeyPath};
throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
throw new SQLServerException(form.format(msgArgs), null, 0, e);
}

// A valid URI.
Expand Down Expand Up @@ -439,7 +439,7 @@ private byte[] AzureKeyVaultWrap(String masterKeyPath,
wrappedKey = keyVaultClient.wrapKeyAsync(masterKeyPath, encryptionAlgorithm, columnEncryptionKey).get();
}
catch (InterruptedException | ExecutionException e) {
throw new SQLServerException(SQLServerException.getErrString("R_EncryptCEKError"), null);
throw new SQLServerException(SQLServerException.getErrString("R_EncryptCEKError"), e);
}
return wrappedKey.getResult();
}
Expand Down Expand Up @@ -472,7 +472,7 @@ private byte[] AzureKeyVaultUnWrap(String masterKeyPath,
unwrappedKey = keyVaultClient.unwrapKeyAsync(masterKeyPath, encryptionAlgorithm, encryptedColumnEncryptionKey).get();
}
catch (InterruptedException | ExecutionException e) {
throw new SQLServerException(SQLServerException.getErrString("R_DecryptCEKError"), null);
throw new SQLServerException(SQLServerException.getErrString("R_DecryptCEKError"), e);
}
return unwrappedKey.getResult();
}
Expand All @@ -496,7 +496,7 @@ private byte[] AzureKeyVaultSignHashedData(byte[] dataToSign,
signedData = keyVaultClient.signAsync(masterKeyPath, JsonWebKeySignatureAlgorithm.RS256, dataToSign).get();
}
catch (InterruptedException | ExecutionException e) {
throw new SQLServerException(SQLServerException.getErrString("R_GenerateSignature"), null);
throw new SQLServerException(SQLServerException.getErrString("R_GenerateSignature"), e);
}
return signedData.getResult();
}
Expand All @@ -522,7 +522,7 @@ private boolean AzureKeyVaultVerifySignature(byte[] dataToVerify,
valid = keyVaultClient.verifyAsync(masterKeyPath, JsonWebKeySignatureAlgorithm.RS256, dataToVerify, signature).get();
}
catch (InterruptedException | ExecutionException e) {
throw new SQLServerException(SQLServerException.getErrString("R_VerifySignature"), null);
throw new SQLServerException(SQLServerException.getErrString("R_VerifySignature"), e);
}

return valid;
Expand All @@ -544,7 +544,7 @@ private int getAKVKeySize(String masterKeyPath) throws SQLServerException {
retrievedKey = keyVaultClient.getKeyAsync(masterKeyPath).get();
}
catch (InterruptedException | ExecutionException e) {
throw new SQLServerException(SQLServerException.getErrString("R_GetAKVKeySize"), null);
throw new SQLServerException(SQLServerException.getErrString("R_GetAKVKeySize"), e);
}

if (!retrievedKey.getKey().getKty().equalsIgnoreCase("RSA") && !retrievedKey.getKey().getKty().equalsIgnoreCase("RSA-HSM")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3370,7 +3370,7 @@ final void processFedAuthInfo(TDSReader tdsReader,
}
catch (Exception e) {
connectionlogger.severe(toString() + "Failed to read FedAuthInfoData.");
throw new SQLServerException(SQLServerException.getErrString("R_FedAuthInfoFailedToReadData"), null);
throw new SQLServerException(SQLServerException.getErrString("R_FedAuthInfoFailedToReadData"), e);
}

if (connectionlogger.isLoggable(Level.FINER)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2134,7 +2134,7 @@ public final ResultSet getGeneratedKeys() throws SQLServerException {
rsPrevious.close();
}
catch (SQLException e) {
throw new SQLServerException(null, e.getMessage(), null, 0, false);
throw new SQLServerException(e.getMessage(), null, 0, e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/microsoft/sqlserver/jdbc/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ static String readUnicodeString(byte[] b,
MessageFormat form = new MessageFormat(txtMsg);
Object[] msgArgs = {new Integer(offset)};
// Re-throw SQLServerException if conversion fails.
throw new SQLServerException(null, form.format(msgArgs), null, 0, true);
throw new SQLServerException(form.format(msgArgs), null, 0, ex);
}

}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/microsoft/sqlserver/jdbc/dtv.java
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ private void sendTemporal(DTV dtv,
throw new SQLServerException(SQLServerException.getErrString("R_zoneOffsetError"), null, // SQLState is null as this error
// is generated in the driver
0, // Use 0 instead of DriverError.NOT_SET to use the correct constructor
null);
e);
}
subSecondNanos = offsetTimeValue.getNano();

Expand Down Expand Up @@ -688,7 +688,7 @@ private void sendTemporal(DTV dtv,
throw new SQLServerException(SQLServerException.getErrString("R_zoneOffsetError"), null, // SQLState is null as this error
// is generated in the driver
0, // Use 0 instead of DriverError.NOT_SET to use the correct constructor
null);
e);
}

subSecondNanos = offsetDateTimeValue.getNano();
Expand Down Expand Up @@ -2230,7 +2230,7 @@ void execute(DTV dtv,
readerValue = new InputStreamReader(inputStreamValue, "US-ASCII");
}
catch (UnsupportedEncodingException ex) {
throw new SQLServerException(null, ex.getMessage(), null, 0, true);
throw new SQLServerException(ex.getMessage(), null, 0, ex);
}

dtv.setValue(readerValue, JavaType.READER);
Expand Down Expand Up @@ -3556,7 +3556,7 @@ Object denormalizedValue(byte[] decryptedValue,
catch (UnsupportedEncodingException e) {
// Important: we should not pass the exception here as it displays the data.
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_unsupportedEncoding"));
throw new SQLServerException(form.format(new Object[] {baseTypeInfo.getCharset()}), null, 0, null);
throw new SQLServerException(form.format(new Object[] {baseTypeInfo.getCharset()}), null, 0, e);
}
}

Expand Down