Skip to content

Commit

Permalink
Extend exception message
Browse files Browse the repository at this point in the history
  • Loading branch information
alex268 committed Dec 1, 2023
1 parent 0c6d34d commit 80c07ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions jdbc/src/main/java/tech/ydb/jdbc/context/YdbExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ public void execute(String msg, Supplier<CompletableFuture<Status>> runnableSupp

public <T> T call(String msg, Supplier<CompletableFuture<Result<T>>> callSupplier) throws SQLException {
if (!isDebug) {
return simpleCall(callSupplier);
return simpleCall(msg, callSupplier);
}

logger.finest(msg);
Stopwatch sw = Stopwatch.createStarted();

try {
T value = simpleCall(callSupplier);
T value = simpleCall(msg, callSupplier);
logger.log(Level.FINEST, "[{0}] OK ", sw.stop());
return value;
} catch (SQLException | RuntimeException ex) {
Expand All @@ -96,21 +96,22 @@ public <T> T call(String msg, Supplier<CompletableFuture<Result<T>>> callSupplie
}
}

private <T> T simpleCall(Supplier<CompletableFuture<Result<T>>> supplier) throws SQLException {
private <T> T simpleCall(String msg, Supplier<CompletableFuture<Result<T>>> supplier) throws SQLException {
try {
Result<T> result = supplier.get().join();
issues.addAll(Arrays.asList(result.getStatus().getIssues()));
return result.getValue();
} catch (UnexpectedResultException ex) {
throw ExceptionFactory.createException(ex);
throw ExceptionFactory.createException("Cannot call '" + msg + "' with " + ex.getStatus(), ex);
}
}

private void simpleExecute(String msg, Supplier<CompletableFuture<Status>> supplier) throws SQLException {
Status status = supplier.get().join();
issues.addAll(Arrays.asList(status.getIssues()));
if (!status.isSuccess()) {
throw ExceptionFactory.createException(new UnexpectedResultException(msg, status));
throw ExceptionFactory.createException("Cannot execute '" + msg + "' with " + status,
new UnexpectedResultException("Unexpected status", status));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ static int getVendorCode(StatusCode code) {
return code.getCode();
}

public static SQLException createException(UnexpectedResultException cause) {
public static SQLException createException(String message, UnexpectedResultException cause) {
StatusCode code = cause.getStatus().getCode();
String sqlState = getSQLState(code);
int vendorCode = getVendorCode(code);

if (code.isRetryable(false)) {
return new YdbRetryableException(cause.getMessage(), sqlState, vendorCode, cause);
return new YdbRetryableException(message, sqlState, vendorCode, cause);
}
if (code.isRetryable(true)) {
return new YdbConditionallyRetryableException(cause.getMessage(), sqlState, vendorCode, cause);
return new YdbConditionallyRetryableException(message, sqlState, vendorCode, cause);
}

return new YdbSQLException(cause.getMessage(), sqlState, vendorCode, cause);
return new YdbSQLException(message, sqlState, vendorCode, cause);
}
}

0 comments on commit 80c07ff

Please sign in to comment.