Skip to content

Expose unexpected decoding exception reason - #5620

Merged
trustin merged 12 commits into
line:mainfrom
Be-poz:expose-exception-reason
Jun 20, 2024
Merged

Expose unexpected decoding exception reason#5620
trustin merged 12 commits into
line:mainfrom
Be-poz:expose-exception-reason

Conversation

@Be-poz

@Be-poz Be-poz commented Apr 18, 2024

Copy link
Copy Markdown
Contributor

Related issue: #5177
Motivation:

AbstractStreamDecoder#decode silently ignores the failure to decode messages.
We probably want to let the caller know a decoding failure has occurred,
instead of silently ignoring and returning an empty result.

Modifications:

  • Modified AbstractStreamDecoder to rethrow the caught exception for all cases.

Result:

@CLAassistant

CLAassistant commented Apr 18, 2024

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions

github-actions Bot commented Apr 18, 2024

Copy link
Copy Markdown
Contributor

🔍 Build Scan® (commit: e3da519)

Job name Status Build Scan®

@ikhoon ikhoon added defect sprint Issues for OSS Sprint participants labels Apr 22, 2024
Comment thread core/src/test/java/com/linecorp/armeria/client/encoding/TestEmbeddedChannel.java Outdated
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.compression.DecompressionException;

class TestStreamDecoder implements StreamDecoder {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What do you think of extending AbstractStreamDecoder instead of copying the code?
If necessary, we may move this class to common.encoding.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That would be great. I've changed this class' directory path. Extending AbstractStreamDecoder for the test class is what i wanted, not recreating the same code. Thanks for allowed to do this.

Comment on lines +58 to +61
throw new UnexpectedDecodeException(
"Unexpected exception has occurred. " +
"This exception is not caused by the buffer reaching max size. Exception message: " +
message);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it is okay to re-throw the exception as is if we don't have additional information for the error message.

That said, your test code is invaluable to verify the code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Your words mean a lot to me. Thank you.

@trustin

trustin commented Apr 23, 2024

Copy link
Copy Markdown
Contributor

And please sign the ICLA 🙇

@Be-poz

Be-poz commented Apr 25, 2024

Copy link
Copy Markdown
Contributor Author

I've signed ICLA. Sorry for missed this.

Comment thread core/src/main/java/com/linecorp/armeria/common/UnexpectedDecodeException.java Outdated
Comment thread core/src/main/java/com/linecorp/armeria/common/UnexpectedDecodeException.java Outdated

@jrhee17 jrhee17 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes look good to me once https://github.com/line/armeria/pull/5620/files#r1574617073 is handled 👍 👍 👍

Comment thread core/src/test/java/com/linecorp/armeria/common/encoding/TestStreamDecoder.java Outdated
Comment thread core/src/test/java/com/linecorp/armeria/common/encoding/TestStreamDecoder.java Outdated
@Be-poz
Be-poz requested a review from jrhee17 May 7, 2024 13:01
@Be-poz

Be-poz commented May 7, 2024

Copy link
Copy Markdown
Contributor Author

I've applied trustin's review.
left one jrhee's comment.

Comment thread core/src/test/java/com/linecorp/armeria/common/encoding/TestStreamDecoder.java Outdated

@minwoox minwoox left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM once @trustin's comments are addressed. 👍

@jrhee17 jrhee17 added this to the 1.29.0 milestone May 9, 2024

@ikhoon ikhoon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, @Be-poz! 🙇‍♂️👍

@trustin trustin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for addressing the comments. Just one last thing 😅

Comment on lines +318 to +324
final ByteBuf mockByteBuf = mock(ByteBuf.class);
final HttpData mockData = mock(HttpData.class);
when(mockData.byteBuf()).thenReturn(mockByteBuf);

final EmbeddedChannel channel = new AlwaysFailureEmbeddedChannel(false);
final StreamDecoder decoder = new TestStreamDecoder(channel, new SnappyFrameDecoder(),
mock(ByteBufAllocator.class), 100);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use a mock only when we really need it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note: ByteBufAllocator doesn't need to be a mock.

@minwoox
minwoox requested a review from trustin June 10, 2024 08:32
@minwoox minwoox modified the milestones: 1.29.0, 1.30.0 Jun 11, 2024

@jrhee17 jrhee17 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 👍 👍

@trustin trustin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks everyone!

@trustin
trustin merged commit 401c3dd into line:main Jun 20, 2024
@trustin

trustin commented Jun 20, 2024

Copy link
Copy Markdown
Contributor

Revised and cleaned up the PR description and commit message, which was previously out of sync.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

defect sprint Issues for OSS Sprint participants

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose the reason why decoding fails for AbstractStreamDecoder

6 participants