Skip to content

Commit 8d7f126

Browse files
authored
Merge pull request #2136 from beyonnex-io/fix-thingDefinitionMigration-dryRun-valitation-issue
fix MigrateThingDefinition wot validation issue
2 parents 0c80cf3 + ce8d94f commit 8d7f126

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

internal/utils/persistent-actors/src/main/java/org/eclipse/ditto/internal/utils/persistentactors/AbstractPersistenceActor.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ public void onStagedQuery(final Command<?> command, final CompletionStage<WithDi
817817
if (command.getDittoHeaders().isResponseRequired()) {
818818
final ActorRef sender = getSender();
819819
response.whenComplete((r, throwable) -> {
820-
if (throwable instanceof DittoRuntimeException dittoRuntimeException) {
820+
if (unwrapThrowable(throwable) instanceof DittoRuntimeException dittoRuntimeException) {
821821
notifySender(sender, dittoRuntimeException);
822822
} else {
823823
notifySender(sender, r);
@@ -840,6 +840,21 @@ public void onError(final DittoRuntimeException error, final Command<?> errorCau
840840
}
841841
}
842842

843+
/**
844+
* Unwraps the root cause of the given {@link Throwable} if it is wrapped inside a {@link CompletionException}.
845+
*
846+
* @param throwable The throwable to unwrap.
847+
* @return The unwrapped cause if the throwable is a {@link CompletionException} and has a cause,
848+
* otherwise returns the original throwable.
849+
*/
850+
protected static Throwable unwrapThrowable(final Throwable throwable) {
851+
if (throwable != null && throwable instanceof CompletionException) {
852+
return throwable.getCause() != null ? throwable.getCause() : throwable;
853+
}
854+
return throwable;
855+
}
856+
857+
843858
/**
844859
* Send a reply and increment access counter.
845860
*

things/service/src/main/java/org/eclipse/ditto/things/service/persistence/actors/ThingPersistenceActor.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.pekko.japi.pf.ReceiveBuilder;
2525
import org.apache.pekko.persistence.RecoveryCompleted;
2626
import org.eclipse.ditto.base.model.acks.DittoAcknowledgementLabel;
27+
import org.eclipse.ditto.base.model.exceptions.DittoRuntimeException;
2728
import org.eclipse.ditto.base.model.exceptions.DittoRuntimeExceptionBuilder;
2829
import org.eclipse.ditto.base.model.headers.DittoHeaders;
2930
import org.eclipse.ditto.base.model.headers.LiveChannelTimeoutStrategy;
@@ -151,14 +152,19 @@ public void onQuery(final Command<?> command, final WithDittoHeaders response) {
151152
public void onStagedQuery(final Command<?> command, final CompletionStage<WithDittoHeaders> response,
152153
@Nullable final StartedSpan startedSpan) {
153154
final ActorRef sender = getSender();
154-
response.thenAccept(r -> {
155-
doOnQuery(command, r, sender);
155+
response.whenComplete((r, throwable) -> {
156+
if (unwrapThrowable(throwable) instanceof DittoRuntimeException dittoRuntimeException) {
157+
notifySender(sender, dittoRuntimeException);
158+
} else {
159+
doOnQuery(command, r, sender);
160+
}
156161
if (startedSpan != null) {
157162
startedSpan.finish();
158163
}
159164
});
160165
}
161166

167+
162168
private void doOnQuery(final Command<?> command, final WithDittoHeaders response, final ActorRef sender) {
163169
if (response.getDittoHeaders().didLiveChannelConditionMatch()) {
164170
final var liveChannelTimeoutStrategy = response.getDittoHeaders()

0 commit comments

Comments
 (0)