From 4e714cbff863a04a39f0f113d81382cf57aa6c53 Mon Sep 17 00:00:00 2001 From: Yuri Sergiichuk Date: Wed, 25 Mar 2020 17:53:20 +0200 Subject: [PATCH 01/10] Add entity class name to the thrown exception --- .../server/entity/RecordBasedRepository.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/server/src/main/java/io/spine/server/entity/RecordBasedRepository.java b/server/src/main/java/io/spine/server/entity/RecordBasedRepository.java index e042b0b03e7..3a9bc439d67 100644 --- a/server/src/main/java/io/spine/server/entity/RecordBasedRepository.java +++ b/server/src/main/java/io/spine/server/entity/RecordBasedRepository.java @@ -150,7 +150,6 @@ public Iterator iterator(Predicate filter) { * if the entity with the given ID is not found in the repository * @throws IllegalStateException * if the repository manages a non-transactional entity type - * * @see Migration * @see #applyMigration(Set, Migration) the batch version of the method */ @@ -188,7 +187,6 @@ void applyMigration(I id, Migration migration) { * * @throws IllegalStateException * if the repository manages a non-transactional entity type - * * @see Migration */ @SuppressWarnings("unchecked") // Checked at runtime. @@ -230,7 +228,8 @@ protected RecordStorage createStorage() { * *

Note: The storage must be assigned before calling this method. * - * @param entities the {@linkplain Entity Entities} to store + * @param entities + * the {@linkplain Entity Entities} to store */ public void store(Collection entities) { Map records = newHashMapWithExpectedSize(entities.size()); @@ -244,7 +243,8 @@ public void store(Collection entities) { /** * Finds an entity with the passed ID. * - * @param id the ID of the entity to find + * @param id + * the ID of the entity to find * @return the entity or {@link Optional#empty()} if there is no entity with such ID */ @Override @@ -257,7 +257,8 @@ public Optional find(I id) { * Finds an entity with the passed ID even if the entity is * {@linkplain WithLifecycle#isActive() active}. * - * @param id the ID of the entity to find + * @param id + * the ID of the entity to find * @return the entity or {@link Optional#empty()} if there is no entity with such ID, * or the entity is not active */ @@ -290,7 +291,8 @@ private Optional findRecord(I id) { * *

The new entity is created if and only if there is no record with the corresponding ID. * - * @param id the ID of the entity to load + * @param id + * the ID of the entity to load * @return the entity with the specified ID */ protected E findOrCreate(I id) { @@ -426,7 +428,7 @@ public Iterator findRecords(TargetFilters filters, ResponseFormat private E findOrThrow(I id) { return find(id).orElseThrow(() -> newIllegalArgumentException( - "An entity with ID `%s` is not found in the repository.", id + "An entity `%s` with ID `%s` is not found in the repository.", entityClass(), id )); } @@ -524,7 +526,7 @@ static class EntityIdFunction implements Function { Message idAsMessage = unpack(idAsAny); @SuppressWarnings("unchecked") - // As the message class is the same as expected, the conversion is safe. + // As the message class is the same as expected, the conversion is safe. I id = (I) idAsMessage; return id; } From d1e1ab2086157a83618d4a2451d2d347170304b6 Mon Sep 17 00:00:00 2001 From: Yuri Sergiichuk Date: Wed, 25 Mar 2020 17:58:40 +0200 Subject: [PATCH 02/10] Add the command ID value to the exception message. --- .../java/io/spine/server/commandbus/CommandAckMonitor.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/io/spine/server/commandbus/CommandAckMonitor.java b/server/src/main/java/io/spine/server/commandbus/CommandAckMonitor.java index 71a40dc4a26..86f2fc3b5e5 100644 --- a/server/src/main/java/io/spine/server/commandbus/CommandAckMonitor.java +++ b/server/src/main/java/io/spine/server/commandbus/CommandAckMonitor.java @@ -112,7 +112,11 @@ private static EventMessage systemEventFor(Status status, CommandId commandId) { .build(); case REJECTION: default: - throw newIllegalArgumentException("Invalid status %s.", status.getStatusCase()); + throw newIllegalArgumentException( + "Command `%s` has invalid status `%s`.", + commandId.getUuid(), + status.getStatusCase() + ); } } From e933122e2adbdd61cb31a4046f781a20e883287b Mon Sep 17 00:00:00 2001 From: Yuri Sergiichuk Date: Wed, 25 Mar 2020 18:02:12 +0200 Subject: [PATCH 03/10] Add more debug information to the exception --- .../src/main/java/io/spine/server/entity/AbstractEntity.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/io/spine/server/entity/AbstractEntity.java b/server/src/main/java/io/spine/server/entity/AbstractEntity.java index 42c87d48e75..e62ae47da1a 100644 --- a/server/src/main/java/io/spine/server/entity/AbstractEntity.java +++ b/server/src/main/java/io/spine/server/entity/AbstractEntity.java @@ -460,8 +460,9 @@ final void updateVersion(Version newVersion) { if (currentVersionNumber > newVersionNumber) { throw newIllegalArgumentException( "A version with the lower number (%d) passed to `updateVersion()` " + - "of the entity with the version number %d.", - newVersionNumber, currentVersionNumber); + "of the entity `%s` (`%s`) with the version number %d.", + newVersionNumber, thisClass(), idAsString(), currentVersionNumber + ); } setVersion(newVersion); } From 03c34e906181da1147f028b26503c972e432583b Mon Sep 17 00:00:00 2001 From: Yuri Sergiichuk Date: Wed, 25 Mar 2020 18:09:17 +0200 Subject: [PATCH 04/10] Add the message itself to provide more context in the exception --- .../spine/server/aggregate/AggregateRepository.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/io/spine/server/aggregate/AggregateRepository.java b/server/src/main/java/io/spine/server/aggregate/AggregateRepository.java index 6481dc5565b..1a137122ce0 100644 --- a/server/src/main/java/io/spine/server/aggregate/AggregateRepository.java +++ b/server/src/main/java/io/spine/server/aggregate/AggregateRepository.java @@ -64,6 +64,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Suppliers.memoize; +import static com.google.protobuf.TextFormat.shortDebugString; import static io.spine.option.EntityOption.Kind.AGGREGATE; import static io.spine.server.aggregate.model.AggregateClass.asAggregateClass; import static io.spine.server.tenant.TenantAwareRunner.with; @@ -431,7 +432,8 @@ private Route eventImportRouting() { I id = ids.stream() .findFirst() .orElseThrow(() -> newIllegalStateException( - "Unable to route import event `%s`.", messageType) + "Unable to route import event `%s`. Event: %s", + messageType, shortDebugString(message)) ); return id; }; @@ -616,9 +618,10 @@ protected A play(I id, AggregateHistory history) { tx.commitIfActive(); if (!success) { lifecycleOf(id).onCorruptedState(outcome); - throw newIllegalStateException("Aggregate %s (ID: %s) cannot be loaded.%n", - aggregateClass().value().getName(), - result.idAsString()); + throw newIllegalStateException( + "Aggregate %s (ID: %s) cannot be loaded.%n", + aggregateClass().value().getName(), result.idAsString() + ); } return result; } From 7421f03ee0cc3d4f1bbe6796d31b92b436b63c9a Mon Sep 17 00:00:00 2001 From: Yuri Sergiichuk Date: Wed, 25 Mar 2020 18:15:31 +0200 Subject: [PATCH 05/10] Pull latest config module --- .idea/inspectionProfiles/Project_Default.xml | 26 +++++++++++++++----- config | 2 +- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index d461f55714e..ce632a0789f 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -74,6 +74,7 @@ + @@ -214,6 +215,7 @@ + @@ -250,6 +252,7 @@ + @@ -324,6 +327,7 @@ +