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

Fix not to raise an exception from `(Service|Client)RequestContext.cu… #2962

Merged
merged 2 commits into from Aug 3, 2020

Conversation

minwoox
Copy link
Member

@minwoox minwoox commented Aug 3, 2020

…rrentOrNull()`

Motivation:
ServiceRequestContext.currentOrNull() raises an IllegalArgumentException
if the current ctx is ClientRequestContext and ctx.root() returns null.

It's very confusing because all other APIs returns null if the name ends with orNull.
So I think the API should return null instead of raising an exception.
We could use ClientRequestContext.roo() to find out if the client call is invoked by a server request or not.

Modification:

  • Returns null instread of raising an exception from (Service|Client)RequestContext.currentOrNull()

Result:

  • (Service|Client)RequestContext.currentOrNull() does not throw an exception anymore.

…rrentOrNull()`

Motivation:
`ServiceRequestContext.currentOrNull()` raises an `IllegalArgumentException`
if the current ctx is `ClientRequestContext` and `ctx.root()` returns `null`.

It's very confusing because all other APIs returns `null` if the name ends with `orNull`.
So I think the API should return `null` instead of raising an exception.
We could use `ClientRequestContext.roo()` to find out if the client call is invoked by a server request or not.

Modification:
- Returns `null` instread of raising an exception from `(Service|Client)RequestContext.currentOrNull()`

Result:
- `(Service|Client)RequestContext.currentOrNull()` does not throw an exception anymore.
@minwoox minwoox added the defect label Aug 3, 2020
@minwoox minwoox added this to the 0.99.9 milestone Aug 3, 2020
@codecov
Copy link

codecov bot commented Aug 3, 2020

Codecov Report

Merging #2962 into master will decrease coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2962      +/-   ##
============================================
- Coverage     73.24%   73.18%   -0.06%     
- Complexity    12211    12213       +2     
============================================
  Files          1062     1058       -4     
  Lines         47343    47380      +37     
  Branches       5979     5995      +16     
============================================
  Hits          34675    34675              
- Misses         9636     9670      +34     
- Partials       3032     3035       +3     
Impacted Files Coverage Δ Complexity Δ
.../linecorp/armeria/client/ClientRequestContext.java 82.05% <100.00%> (-6.19%) 18.00 <2.00> (+1.00) ⬇️
...linecorp/armeria/server/ServiceRequestContext.java 86.84% <100.00%> (-7.45%) 19.00 <0.00> (ø)
...a/common/grpc/protocol/ArmeriaStatusException.java 57.14% <0.00%> (-42.86%) 2.00% <0.00%> (-1.00%)
...corp/armeria/internal/common/TimeoutScheduler.java 77.61% <0.00%> (-11.93%) 70.00% <0.00%> (+36.00%) ⬇️
...om/linecorp/armeria/client/HttpSessionHandler.java 72.78% <0.00%> (-8.29%) 50.00% <0.00%> (-3.00%)
...armeria/internal/common/grpc/HttpStreamReader.java 79.76% <0.00%> (-4.77%) 23.00% <0.00%> (-3.00%)
...ria/common/grpc/protocol/ArmeriaMessageFramer.java 90.76% <0.00%> (-2.89%) 25.00% <0.00%> (ø%)
...inecorp/armeria/server/HttpResponseSubscriber.java 78.94% <0.00%> (-2.48%) 56.00% <0.00%> (-5.00%)
... and 34 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 878684c...d176bea. Read the comment docs.

Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

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

Thanks! @minwoox

@trustin trustin merged commit 2848c4d into line:master Aug 3, 2020
fmguerreiro pushed a commit to fmguerreiro/armeria that referenced this pull request Sep 19, 2020
line#2962)

* Fix not to raise an exception from `(Service|Client)RequestContext.currentOrNull()`
Motivation:
`ServiceRequestContext.currentOrNull()` raises an `IllegalArgumentException`
if the current ctx is `ClientRequestContext` and `ctx.root()` returns `null`.

It's very confusing because all other APIs returns `null` if the name ends with `orNull`.
So I think the API should return `null` instead of raising an exception.
We could use `ClientRequestContext.roo()` to find out if the client call is invoked by a server request or not.

Modification:
- Returns `null` instread of raising an exception from `(Service|Client)RequestContext.currentOrNull()`

Result:
- `(Service|Client)RequestContext.currentOrNull()` does not throw an exception anymore.

* Address the comment by @trustin
@minwoox minwoox deleted the serviceContextCurrentOrNull branch March 29, 2023 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants