Fix issue with nested anon structs in source code#253
Closed
Fix issue with nested anon structs in source code#253
Conversation
Author
|
@long-nt-tran pointed out that the issue here is that the repo is geared around using a fixed version of the tool. (And not just keeping up with the latest.) The key piece is using the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed?
mockgen-fixwould fail to format updated source code if the mock struct contained a field with an anonymous struct type (struct{}).--verboseflag to print out the code being modified, to make it easier to debug errors during the formatting step.Why?
I was unable to run
make protobecause themockgen-fixstep was failing with the following error:As it turns out, there is a minor bug in the implementation. The version of
mockgenI have on my machine (v0.6.0) apparently emits the expected struct with a new field that causes the logic for finding the "end of the struct}".285: // MockOperatorServiceServer is a mock of OperatorServiceServer interface. 286: type MockOperatorServiceServer struct { 287: ctrl *gomock.Controller 288: recorder *MockOperatorServiceServerMockRecorder + 289: isgomock struct{} 290: }So the actual fix is just changing this line, ensuring that we find the first
}character at the start of the line. (And not the last character ofisgomock struct{}.)But this PR includes the additional refactorings I used to look into this.
How did you test it?
Just ran it locally. Now things work as expected.
Potential risks
If the proto compiler emits Go code where structs don't end with their last
}at the beginning of the line, thenmockgen-fixwill start failing in CI.BONUS: When did this break?!?
I'm a little confused why I am running into problems here. After some quick searching:
So... could it be the case that everyone using
mockgenis on a version from 10/2024? And I'm only hitting this because I just rango install go.uber.org/mock/mockgen@latestthis afternoon?That is plausible, but doesn't sound right...