Skip to content

Commit 8822e3b

Browse files
authored
chore(executor): print stack trace for exceptions (#3469)
1 parent 0cdc96d commit 8822e3b

File tree

1 file changed

+42
-34
lines changed

1 file changed

+42
-34
lines changed

google-cloud-spanner-executor/src/main/java/com/google/cloud/executor/spanner/CloudClientExecutor.java

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,12 @@ public synchronized Status startBatchTxn(
623623
} catch (SpannerException e) {
624624
return sender.finishWithError(toStatus(e));
625625
} catch (Exception e) {
626+
LOGGER.log(Level.WARNING, "Unexpected error: " + e.getMessage());
626627
return sender.finishWithError(
627628
toStatus(
628629
SpannerExceptionFactory.newSpannerException(
629-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
630+
ErrorCode.INVALID_ARGUMENT,
631+
CloudClientExecutor.unexpectedExceptionResponse(e))));
630632
}
631633
}
632634

@@ -730,7 +732,8 @@ public synchronized Status finish(Mode finishMode, OutcomeSender sender) {
730732
return sender.finishWithError(
731733
toStatus(
732734
SpannerExceptionFactory.newSpannerException(
733-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
735+
ErrorCode.INVALID_ARGUMENT,
736+
CloudClientExecutor.unexpectedExceptionResponse(e))));
734737
}
735738
return sender.sendOutcome(outcomeBuilder.build());
736739
} else if (batchTxn != null) {
@@ -1075,7 +1078,7 @@ private Status executeAction(
10751078
return outcomeSender.finishWithError(
10761079
toStatus(
10771080
SpannerExceptionFactory.newSpannerException(
1078-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1081+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
10791082
} finally {
10801083
scope.close();
10811084
span.end();
@@ -1171,7 +1174,7 @@ private Status executeAdminAction(
11711174
return outcomeSender.finishWithError(
11721175
toStatus(
11731176
SpannerExceptionFactory.newSpannerException(
1174-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1177+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
11751178
}
11761179
}
11771180

@@ -1260,7 +1263,7 @@ private Status executeUpdateCloudInstance(
12601263
return sender.finishWithError(
12611264
toStatus(
12621265
SpannerExceptionFactory.newSpannerException(
1263-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1266+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
12641267
}
12651268
return sender.finishWithOK();
12661269
}
@@ -1282,7 +1285,7 @@ private Status executeDeleteCloudInstance(
12821285
return sender.finishWithError(
12831286
toStatus(
12841287
SpannerExceptionFactory.newSpannerException(
1285-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1288+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
12861289
}
12871290
return sender.finishWithOK();
12881291
}
@@ -1330,7 +1333,7 @@ private Status executeListCloudInstances(
13301333
return sender.finishWithError(
13311334
toStatus(
13321335
SpannerExceptionFactory.newSpannerException(
1333-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1336+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
13341337
}
13351338
}
13361339

@@ -1374,7 +1377,7 @@ private Status executeListCloudInstanceConfigs(
13741377
return sender.finishWithError(
13751378
toStatus(
13761379
SpannerExceptionFactory.newSpannerException(
1377-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1380+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
13781381
}
13791382
}
13801383

@@ -1405,7 +1408,7 @@ private Status executeGetCloudInstanceConfig(
14051408
return sender.finishWithError(
14061409
toStatus(
14071410
SpannerExceptionFactory.newSpannerException(
1408-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1411+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
14091412
}
14101413
}
14111414

@@ -1436,7 +1439,7 @@ private Status executeGetCloudInstance(
14361439
return sender.finishWithError(
14371440
toStatus(
14381441
SpannerExceptionFactory.newSpannerException(
1439-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1442+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
14401443
}
14411444
}
14421445

@@ -1466,7 +1469,7 @@ private Status executeCreateUserInstanceConfig(
14661469
return sender.finishWithError(
14671470
toStatus(
14681471
SpannerExceptionFactory.newSpannerException(
1469-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1472+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
14701473
}
14711474
return sender.finishWithOK();
14721475
}
@@ -1486,7 +1489,7 @@ private Status executeDeleteUserInstanceConfig(
14861489
return sender.finishWithError(
14871490
toStatus(
14881491
SpannerExceptionFactory.newSpannerException(
1489-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1492+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
14901493
}
14911494
return sender.finishWithOK();
14921495
}
@@ -1515,7 +1518,7 @@ private Status executeCreateCloudCustomEncryptedDatabase(
15151518
return sender.finishWithError(
15161519
toStatus(
15171520
SpannerExceptionFactory.newSpannerException(
1518-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1521+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
15191522
}
15201523
return sender.finishWithOK();
15211524
}
@@ -1550,7 +1553,7 @@ private Status executeCreateCloudDatabase(
15501553
return sender.finishWithError(
15511554
toStatus(
15521555
SpannerExceptionFactory.newSpannerException(
1553-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1556+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
15541557
}
15551558
return sender.finishWithOK();
15561559
}
@@ -1584,7 +1587,7 @@ private Status executeUpdateCloudDatabaseDdl(
15841587
return sender.finishWithError(
15851588
toStatus(
15861589
SpannerExceptionFactory.newSpannerException(
1587-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1590+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
15881591
}
15891592
return sender.finishWithOK();
15901593
}
@@ -1605,7 +1608,7 @@ private Status executeDropCloudDatabase(
16051608
return sender.finishWithError(
16061609
toStatus(
16071610
SpannerExceptionFactory.newSpannerException(
1608-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1611+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
16091612
}
16101613
return sender.finishWithOK();
16111614
}
@@ -1642,7 +1645,7 @@ private Status executeCreateCloudBackup(
16421645
return sender.finishWithError(
16431646
toStatus(
16441647
SpannerExceptionFactory.newSpannerException(
1645-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1648+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
16461649
}
16471650
}
16481651

@@ -1678,7 +1681,7 @@ private Status executeCopyCloudBackup(
16781681
return sender.finishWithError(
16791682
toStatus(
16801683
SpannerExceptionFactory.newSpannerException(
1681-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1684+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
16821685
}
16831686
}
16841687

@@ -1709,7 +1712,7 @@ private Status executeGetCloudBackup(
17091712
return sender.finishWithError(
17101713
toStatus(
17111714
SpannerExceptionFactory.newSpannerException(
1712-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1715+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
17131716
}
17141717
}
17151718

@@ -1743,7 +1746,7 @@ private Status executeUpdateCloudBackup(
17431746
return sender.finishWithError(
17441747
toStatus(
17451748
SpannerExceptionFactory.newSpannerException(
1746-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1749+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
17471750
}
17481751
}
17491752

@@ -1763,7 +1766,7 @@ private Status executeDeleteCloudBackup(
17631766
return sender.finishWithError(
17641767
toStatus(
17651768
SpannerExceptionFactory.newSpannerException(
1766-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1769+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
17671770
}
17681771
}
17691772

@@ -1803,7 +1806,7 @@ private Status executeListCloudBackups(
18031806
return sender.finishWithError(
18041807
toStatus(
18051808
SpannerExceptionFactory.newSpannerException(
1806-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1809+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
18071810
}
18081811
}
18091812

@@ -1840,7 +1843,7 @@ private Status executeListCloudBackupOperations(
18401843
return sender.finishWithError(
18411844
toStatus(
18421845
SpannerExceptionFactory.newSpannerException(
1843-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1846+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
18441847
}
18451848
}
18461849

@@ -1879,7 +1882,7 @@ private Status executeListCloudDatabases(
18791882
return sender.finishWithError(
18801883
toStatus(
18811884
SpannerExceptionFactory.newSpannerException(
1882-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1885+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
18831886
}
18841887
}
18851888

@@ -1918,7 +1921,7 @@ private Status executeListCloudDatabaseOperations(
19181921
return sender.finishWithError(
19191922
toStatus(
19201923
SpannerExceptionFactory.newSpannerException(
1921-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1924+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
19221925
}
19231926
}
19241927

@@ -1952,7 +1955,7 @@ private Status executeRestoreCloudDatabase(
19521955
return sender.finishWithError(
19531956
toStatus(
19541957
SpannerExceptionFactory.newSpannerException(
1955-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1958+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
19561959
}
19571960
}
19581961

@@ -1983,7 +1986,7 @@ private Status executeGetCloudDatabase(
19831986
return sender.finishWithError(
19841987
toStatus(
19851988
SpannerExceptionFactory.newSpannerException(
1986-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
1989+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
19871990
}
19881991
}
19891992

@@ -2011,7 +2014,7 @@ private Status executeGetOperation(
20112014
return sender.finishWithError(
20122015
toStatus(
20132016
SpannerExceptionFactory.newSpannerException(
2014-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
2017+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
20152018
}
20162019
}
20172020

@@ -2030,7 +2033,7 @@ private Status executeCancelOperation(
20302033
return sender.finishWithError(
20312034
toStatus(
20322035
SpannerExceptionFactory.newSpannerException(
2033-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
2036+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
20342037
}
20352038
}
20362039

@@ -2120,10 +2123,11 @@ private Status executeGenerateDbPartitionsRead(
21202123
LOGGER.log(Level.WARNING, String.format("GenerateDbPartitionsRead failed for %s", action));
21212124
return sender.finishWithError(toStatus(e));
21222125
} catch (Exception e) {
2126+
LOGGER.log(Level.WARNING, "Unexpected error: " + e.getMessage());
21232127
return sender.finishWithError(
21242128
toStatus(
21252129
SpannerExceptionFactory.newSpannerException(
2126-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
2130+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
21272131
}
21282132
}
21292133

@@ -2166,10 +2170,11 @@ private Status executeGenerateDbPartitionsQuery(
21662170
LOGGER.log(Level.WARNING, String.format("GenerateDbPartitionsQuery failed for %s", action));
21672171
return sender.finishWithError(toStatus(e));
21682172
} catch (Exception e) {
2173+
LOGGER.log(Level.WARNING, "Unexpected error: " + e.getMessage());
21692174
return sender.finishWithError(
21702175
toStatus(
21712176
SpannerExceptionFactory.newSpannerException(
2172-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
2177+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
21732178
}
21742179
}
21752180

@@ -2198,10 +2203,11 @@ private Status executeExecutePartition(
21982203
} catch (SpannerException e) {
21992204
return sender.finishWithError(toStatus(e));
22002205
} catch (Exception e) {
2206+
LOGGER.log(Level.WARNING, "Unexpected error: " + e.getMessage());
22012207
return sender.finishWithError(
22022208
toStatus(
22032209
SpannerExceptionFactory.newSpannerException(
2204-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
2210+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
22052211
}
22062212
}
22072213

@@ -2225,10 +2231,11 @@ private Status executePartitionedUpdate(
22252231
} catch (SpannerException e) {
22262232
return sender.finishWithError(toStatus(e));
22272233
} catch (Exception e) {
2234+
LOGGER.log(Level.WARNING, "Unexpected error: " + e.getMessage());
22282235
return sender.finishWithError(
22292236
toStatus(
22302237
SpannerExceptionFactory.newSpannerException(
2231-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
2238+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
22322239
}
22332240
}
22342241

@@ -2478,10 +2485,11 @@ private Status executeStartTxn(
24782485
} catch (SpannerException e) {
24792486
return sender.finishWithError(toStatus(e));
24802487
} catch (Exception e) {
2488+
LOGGER.log(Level.WARNING, "Unexpected error: " + e.getMessage());
24812489
return sender.finishWithError(
24822490
toStatus(
24832491
SpannerExceptionFactory.newSpannerException(
2484-
ErrorCode.INVALID_ARGUMENT, "Unexpected error: " + e.getMessage())));
2492+
ErrorCode.INVALID_ARGUMENT, CloudClientExecutor.unexpectedExceptionResponse(e))));
24852493
}
24862494
}
24872495

0 commit comments

Comments
 (0)