Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make exceptions a bit more informative #1255

Merged
merged 10 commits into from
Mar 25, 2020

Conversation

yuri-sergiichuk
Copy link
Contributor

In the PR I have added some more informative context to exceptions thrown by the framework.

The initial trigger for the change was an exception thrown by the migration process with as little info as:

java.lang.IllegalArgumentException: An entity with ID `order_id {
  date {
    year: 2020
    month: JANUARY
    day: 15
  }
  number: 1
}
` is not found in the repository.
	at io.spine.util.Exceptions.newIllegalArgumentException(Exceptions.java:164)
	at io.spine.server.entity.RecordBasedRepository.lambda$findOrThrow$1(RecordBasedRepository.java:428)

@yuri-sergiichuk yuri-sergiichuk self-assigned this Mar 25, 2020
@codecov
Copy link

codecov bot commented Mar 25, 2020

Codecov Report

Merging #1255 into master will increase coverage by 0.00%.
The diff coverage is 80.00%.

@@            Coverage Diff            @@
##             master    #1255   +/-   ##
=========================================
  Coverage     91.09%   91.10%           
  Complexity     4641     4641           
=========================================
  Files           596      596           
  Lines         14678    14683    +5     
  Branches        831      831           
=========================================
+ Hits          13371    13377    +6     
  Misses         1046     1046           
+ Partials        261      260    -1     

@@ -74,6 +74,7 @@
<inspection_tool class="BigDecimalEquals" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="BreakStatement" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="BreakStatementWithLabel" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="BusyWait" enabled="true" level="WARNING" enabled_by_default="true" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please synchronize this file with the config module. It might be that your local settings are infiltrating the repository.

Copy link
Contributor Author

@yuri-sergiichuk yuri-sergiichuk Mar 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually got these changes from the config/pull. Right now they are identical.

@@ -431,7 +432,8 @@ final void importEvent(EventEnvelope event) {
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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging an event body is a security concern. Please only log the meta-data, such as event ID and timestamp.

throw newIllegalStateException("Aggregate %s (ID: %s) cannot be loaded.%n",
aggregateClass().value().getName(),
result.idAsString());
throw newIllegalStateException(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert the formatting. The policy is not to split the method and the first param if possible, i.e. if the char count is not too big.

aggregateClass().value().getName(),
result.idAsString());
throw newIllegalStateException(
"Aggregate %s (ID: %s) cannot be loaded.%n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Aggregate %s (ID: %s) cannot be loaded.%n",
"Aggregate `%s` (ID: %s) cannot be loaded.%n",

@@ -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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this error popped up in your log? If so, this is a bug or a compatibility issue worth paying attention to. Let's discuss if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, not really. I looked over the other messages that could have a bit more useful info.

@@ -426,7 +428,7 @@ protected E findOrCreate(I id) {

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure the word class is not added to the message before the class name.

Copy link
Contributor

@dmdashenkov dmdashenkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yuri-sergiichuk, LGTM with a single comment to address.

@@ -431,7 +431,8 @@ final void importEvent(EventEnvelope event) {
I id = ids.stream()
.findFirst()
.orElseThrow(() -> newIllegalStateException(
"Unable to route import event `%s`.", messageType)
"Unable to route import event `%s`. Event: %s",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's still a placeholder left.

@yuri-sergiichuk yuri-sergiichuk merged commit 6df1389 into master Mar 25, 2020
@yuri-sergiichuk yuri-sergiichuk deleted the make-exceptions-informative branch March 25, 2020 18:06
@dmitrykuzmin dmitrykuzmin mentioned this pull request Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants