From afa5847105831f6ee5f855380cf61977b70ef1c1 Mon Sep 17 00:00:00 2001 From: Andreas Fankhauser <23085769+hiddenalpha@users.noreply.github.com> Date: Fri, 5 Jul 2024 10:53:40 +0200 Subject: [PATCH] Fix missing 'cause' arg for newReplyException() --- .../redisques/QueueStatsService.java | 2 +- .../exception/NoStackReplyException.java | 30 ------------------- .../exception/RedisQuesExceptionFactory.java | 2 +- .../ThriftyRedisQuesExceptionFactory.java | 11 +++++-- .../WastefulRedisQuesExceptionFactory.java | 7 +++-- .../handler/GetQueuesItemsCountHandler.java | 2 +- 6 files changed, 17 insertions(+), 37 deletions(-) delete mode 100644 src/main/java/org/swisspush/redisques/exception/NoStackReplyException.java diff --git a/src/main/java/org/swisspush/redisques/QueueStatsService.java b/src/main/java/org/swisspush/redisques/QueueStatsService.java index 164cc30..d9a3bdc 100644 --- a/src/main/java/org/swisspush/redisques/QueueStatsService.java +++ b/src/main/java/org/swisspush/redisques/QueueStatsService.java @@ -73,7 +73,7 @@ public QueueStatsService( public void getQueueStats(CTX mCtx, GetQueueStatsMentor mentor) { if (!incomingRequestQuota.tryAcquire()) { Throwable ex = exceptionFactory.newReplyException(RECIPIENT_FAILURE, 429, - "Server too busy to handle yet-another-queue-stats-request now"); + "Server too busy to handle yet-another-queue-stats-request now", null); vertx.runOnContext(v -> mentor.onError(ex, mCtx)); return; } diff --git a/src/main/java/org/swisspush/redisques/exception/NoStackReplyException.java b/src/main/java/org/swisspush/redisques/exception/NoStackReplyException.java deleted file mode 100644 index 93c9901..0000000 --- a/src/main/java/org/swisspush/redisques/exception/NoStackReplyException.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.swisspush.redisques.exception; - -import io.vertx.core.eventbus.ReplyFailure; - -/** - * There was once a fix in vertx for this (https://github.com/eclipse-vertx/vert.x/issues/4840) - * but for whatever reason in our case we still see stack-trace recordings. Passing - * this subclass to {@link io.vertx.core.eventbus.Message#reply(Object)} seems to - * do the trick. - */ -public class NoStackReplyException extends io.vertx.core.eventbus.ReplyException { - - public NoStackReplyException(ReplyFailure failureType, int failureCode, String message) { - super(failureType, failureCode, message); - } - - public NoStackReplyException(ReplyFailure failureType, String message) { - this(failureType, -1, message); - } - - public NoStackReplyException(ReplyFailure failureType) { - this(failureType, -1, null); - } - - @Override - public Throwable fillInStackTrace() { - return this; - } - -} diff --git a/src/main/java/org/swisspush/redisques/exception/RedisQuesExceptionFactory.java b/src/main/java/org/swisspush/redisques/exception/RedisQuesExceptionFactory.java index ea6d45f..493b5e4 100644 --- a/src/main/java/org/swisspush/redisques/exception/RedisQuesExceptionFactory.java +++ b/src/main/java/org/swisspush/redisques/exception/RedisQuesExceptionFactory.java @@ -30,7 +30,7 @@ public interface RedisQuesExceptionFactory { public RuntimeException newRuntimeException(String message, Throwable cause); - public ReplyException newReplyException(ReplyFailure failureType, int failureCode, String msg); + public ReplyException newReplyException(ReplyFailure failureType, int failureCode, String msg, Throwable cause); /** diff --git a/src/main/java/org/swisspush/redisques/exception/ThriftyRedisQuesExceptionFactory.java b/src/main/java/org/swisspush/redisques/exception/ThriftyRedisQuesExceptionFactory.java index 73ced1f..805cc29 100644 --- a/src/main/java/org/swisspush/redisques/exception/ThriftyRedisQuesExceptionFactory.java +++ b/src/main/java/org/swisspush/redisques/exception/ThriftyRedisQuesExceptionFactory.java @@ -33,8 +33,15 @@ public RuntimeException newRuntimeException(String message, Throwable cause) { } @Override - public ReplyException newReplyException(ReplyFailure failureType, int failureCode, String msg) { - return new NoStackReplyException(failureType, failureCode, msg); + public ReplyException newReplyException(ReplyFailure failureType, int failureCode, String msg, Throwable cause) { + // There was once a fix in vertx for this (https://github.com/eclipse-vertx/vert.x/issues/4840) + // but for whatever reason in our case we still see stack-trace recordings. Passing + // this subclass to {@link io.vertx.core.eventbus.Message#reply(Object)} seems to + // do the trick. + if (msg == null && cause != null) msg = cause.getMessage(); + return new ReplyException(failureType, failureCode, msg) { + @Override public Throwable fillInStackTrace() { return this; } + }; } @Override diff --git a/src/main/java/org/swisspush/redisques/exception/WastefulRedisQuesExceptionFactory.java b/src/main/java/org/swisspush/redisques/exception/WastefulRedisQuesExceptionFactory.java index cb7329f..a3190d5 100644 --- a/src/main/java/org/swisspush/redisques/exception/WastefulRedisQuesExceptionFactory.java +++ b/src/main/java/org/swisspush/redisques/exception/WastefulRedisQuesExceptionFactory.java @@ -26,8 +26,11 @@ public RuntimeException newRuntimeException(String message, Throwable cause) { } @Override - public ReplyException newReplyException(ReplyFailure failureType, int failureCode, String msg) { - return new ReplyException(failureType, failureCode, msg); + public ReplyException newReplyException(ReplyFailure failureType, int failureCode, String msg, Throwable cause) { + if (msg == null && cause != null) msg = cause.getMessage(); + ReplyException ex = new ReplyException(failureType, failureCode, msg); + if (cause != null) ex.initCause(cause); + return ex; } @Override diff --git a/src/main/java/org/swisspush/redisques/handler/GetQueuesItemsCountHandler.java b/src/main/java/org/swisspush/redisques/handler/GetQueuesItemsCountHandler.java index 90788aa..7cf2d09 100644 --- a/src/main/java/org/swisspush/redisques/handler/GetQueuesItemsCountHandler.java +++ b/src/main/java/org/swisspush/redisques/handler/GetQueuesItemsCountHandler.java @@ -88,7 +88,7 @@ public void handle(AsyncResult handleQueues) { } if (redisRequestQuota.availablePermits() <= 0) { event.reply(exceptionFactory.newReplyException(ReplyFailure.RECIPIENT_FAILURE, 429, - "Too many simultaneous '" + GetQueuesItemsCountHandler.class.getSimpleName() + "' requests in progress")); + "Too many simultaneous '" + GetQueuesItemsCountHandler.class.getSimpleName() + "' requests in progress", null)); return; }