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

Expose unexpected decoding exception reason #5620

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

Be-poz
Copy link

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

Motivation:

Issue: #5177

Modifications:

  • I added UnexpectedDecodeException to throw an exception if a DecompressionException is thrown and the if condition is not met.
  • Added tests ( I decided that it is important that the decoder throws a DecompressionException and that understanding the internal implementation of the decoder is not what i am testing, so i decided to use a mock at the first time. However, it was difficult to use 'mock' because the 'decoder' variable is created and initialized in the constructor instead of being injected, and it was difficult to manipulate it using inheritance because the access modifier level of the constructor of AbstractStreamDecoder is 'protected'. Therefore, I added two separate classes for testing. I don't think this �structure is efficient, and I think it's hard to manage when AbstractStreamDecoder class changes are made. I couldn't think of any other way to do it, so I went with this, but if anyone has a better idea, I'd love to hear it.

Result:

@CLAassistant
Copy link

CLAassistant commented Apr 18, 2024

CLA assistant check
All committers have signed the CLA.

@ikhoon ikhoon added defect sprint Issues for OSS Sprint participants labels Apr 22, 2024
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.compression.DecompressionException;

class TestStreamDecoder implements StreamDecoder {
Copy link
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
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
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
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
Copy link
Member

trustin commented Apr 23, 2024

And please sign the ICLA 🙇

@Be-poz
Copy link
Author

Be-poz commented Apr 25, 2024

I've signed ICLA. Sorry for missed this.

Copy link
Contributor

@jrhee17 jrhee17 left a comment

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 👍 👍 👍

@Be-poz Be-poz requested a review from jrhee17 May 7, 2024 13:01
@Be-poz
Copy link
Author

Be-poz commented May 7, 2024

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

Copy link
Member

@minwoox minwoox left a comment

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
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