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

Improve readability of proto decode exception message #2768

Merged
merged 6 commits into from
Aug 22, 2024

Conversation

xiaozhikang0916
Copy link
Contributor

Found it hard to debug when exceptions with message like Expected wire type 0, but found 1 were got. This PR is about to make some improvement of these messages for better tracability and readability.

  1. Wrap definition of wire types with enum class ProtoWireType to show both name and id in message,
  2. Catch and rethrow any ProtobufDecodingException in most decodeXXX functions, with proto number and type name in new exception message.

@xiaozhikang0916
Copy link
Contributor Author

@sandwwraith can you take a look on this PR?

@sandwwraith
Copy link
Member

@xiaozhikang0916 sure

@sandwwraith
Copy link
Member

It seems there are some tests failing

val currentMessage = message[index]
assertNotNull(currentException, "Expected exception to have a cause with message $currentMessage, but it was null")
require(currentException != null)
assertEquals(currentMessage, currentException.message, "Expected exception to have a cause with message <$currentMessage>, but it was <${currentException.message}> at cause stack ${index + depth}")
Copy link
Member

Choose a reason for hiding this comment

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

IDEA can show nice 'Click to see the difference' pop-up to compare between expected and actual values on test failure, but only if the exception message satisfies JUnit4's exception message regex (https://stackoverflow.com/questions/10934743/formatting-output-so-that-intellij-idea-shows-diffs-for-two-texts). So you may want to rephrase your message a bit for it to include expected:<bla-blah> but was:<blah-blah-blah> substring.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After diving into assertEquals I found that it would append the Expected <$expected>, actual <$actual>. string after message passing in. So I would just simplify the input message.

It works in my IntelliJ IDEA 2024.2.1 RC and you can comment out the Ignore annotation in the new TestFunctionTest to see if it also works in other environments. And since these tests are for checking IDEA behaviours, I would just leave it failing, not wraping another assertFailWith with message check.

Copy link
Member

@sandwwraith sandwwraith left a comment

Choose a reason for hiding this comment

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

Thanks for all your efforts!

@sandwwraith sandwwraith merged commit 0b5145c into Kotlin:dev Aug 22, 2024
3 checks passed
@xiaozhikang0916 xiaozhikang0916 deleted the feature/wire-type-message branch August 23, 2024 02:06
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.

3 participants