Skip to content

Commit 8999747

Browse files
committed
Keep exception’s caused by when re-throwing
1 parent e0ac210 commit 8999747

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

core/src/main/java/de/bwaldvogel/mongo/backend/AbstractMongoCollection.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,8 @@ public Document findAndModify(Document query) {
414414
oldDocument = updateDocument(document, updateQuery, arrayFilters, matchPos);
415415
} catch (MongoServerError e) {
416416
if (e.shouldPrefixCommandContext()) {
417-
String prefix = "Plan executor error during findAndModify :: caused by :: ";
418-
throw new MongoServerError(e.getCode(), e.getCodeName(), prefix + e.getMessageWithoutErrorCode());
417+
throw new FindAndModifyPlanExecutorError(e);
418+
419419
} else {
420420
throw e;
421421
}
@@ -457,6 +457,17 @@ public Document findAndModify(Document query) {
457457
return result;
458458
}
459459

460+
private static class FindAndModifyPlanExecutorError extends MongoServerError {
461+
462+
private static final long serialVersionUID = 1L;
463+
464+
private static final String PREFIX = "Plan executor error during findAndModify :: caused by :: ";
465+
466+
private FindAndModifyPlanExecutorError(MongoServerError cause) {
467+
super(cause.getCode(), cause.getCodeName(), PREFIX + cause.getMessageWithoutErrorCode(), cause);
468+
}
469+
}
470+
460471
@Override
461472
public QueryResult handleQuery(QueryParameters queryParameters) {
462473
final Document query;

core/src/main/java/de/bwaldvogel/mongo/backend/aggregation/Aggregation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public boolean isModifying() {
272272
return stages.stream().anyMatch(AggregationStage::isModifying);
273273
}
274274

275-
public static class PlanExecutorError extends MongoServerError {
275+
private static class PlanExecutorError extends MongoServerError {
276276

277277
private static final long serialVersionUID = 1L;
278278

0 commit comments

Comments
 (0)