-
Notifications
You must be signed in to change notification settings - Fork 24.6k
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
Improve mechanism for extracting the result of a PlainActionFuture #110019
Improve mechanism for extracting the result of a PlainActionFuture #110019
Conversation
server/src/main/java/org/elasticsearch/action/support/PlainActionFuture.java
Show resolved
Hide resolved
return future.result(); | ||
} catch (ExecutionException e) { | ||
throw new UncategorizedExecutionException("An error occurred fetching timestamp field type for " + index, e); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not quite the same as before, I believe previously, if there was a RuntimeException
it would be thrown directly, and if there was a checked exception the behaviour would be consistent with the above. But looking up the call stack there doesn't appear to be any behaviour specific to the exception thrown. I'm happy to try and restore the original behaviour but fear it might just be adding noise to be consistent with something that nobody was depending on in the first place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think this is ok, indeed possibly preferable, because now we get the call stack to the .result()
call as well as the one which failed the future.
throw e; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this down the hierarchy as it's used to prevent excessive nesting of execution exceptions here, but this one is private.
Hi @nicktindall, I've created a changelog YAML for you. |
Pinging @elastic/es-distributed (Team:Distributed) |
} catch (Exception e) { | ||
return fail(e); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be controversial. As the javadoc suggests it's just to reduce boilerplate in places where we don't want checked exceptions to propagate, and we don't expect them to occur. There's something like this in JUnit 5.
Perhaps there's already a utility for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I'd be inclined to call it safeGet
since it's kinda doing the same thing as safeGet(Future<T>)
, getting a result and asserting that this succeeded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
return future.result(); | ||
} catch (ExecutionException e) { | ||
throw new UncategorizedExecutionException("An error occurred fetching timestamp field type for " + index, e); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think this is ok, indeed possibly preferable, because now we get the call stack to the .result()
call as well as the one which failed the future.
…_result # Conflicts: # test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java
result()
is called on aPlainActionFuture
that completed exceptionallynew ExecutionException(cause)
PlainActionFuture#actionResult()
as it makes less sense with the consistent wrappingCloses #108125