Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

fix callserrors with empty msg#292

Closed
mjaow wants to merge 2 commits intogolang:masterfrom
mjaow:bugfix/no-message-callserrors
Closed

fix callserrors with empty msg#292
mjaow wants to merge 2 commits intogolang:masterfrom
mjaow:bugfix/no-message-callserrors

Conversation

@mjaow
Copy link
Copy Markdown

@mjaow mjaow commented May 10, 2019

Fix #291

check exhaustedNum and callsErrors.len() , if it's true, fill with error msg

@balshetzer
Copy link
Copy Markdown
Collaborator

balshetzer commented May 17, 2019

I don't understand this fix. Can you explain it?

If the reason a call doesn't match an expectation is an InOrder then matches will return an error saying that. So why do you believe that f exhaustedNum > 0 && callsErrors.Len() == 0 indicates an ordering issue?

@mjaow
Copy link
Copy Markdown
Author

mjaow commented May 18, 2019

@balshetzer
i thought it was a order issue caused in concurrent invoke.
1.callsErrors.Len() means all method matches
2.exhaustedNum >0 (and expectedNum==0) means the method shouldn't be here, should be in prev position
according two reason,I concluded it was a order issue

Sorry,I couldn't think of another better reason to describe and I thought it was the simplest way to fix it

@cvgw
Copy link
Copy Markdown
Collaborator

cvgw commented Dec 27, 2019

Some additional info
There is a case where matches will return nil for an ordering error.
e.g.

gomock.InOrder(
  mockFoo.EXPECT().Foo().AnyTimes(),
  mockBar.EXPECT().Bar().AnyTimes(),
  mockBaz.EXPECT().Baz().AnyTimes(),
)

mockFoo.Foo()
mockBar.Bar()
mockFoo.Foo()

This will produce an error message with no additional information following because: (as reported in the issue)

err will always be nil

if err := call.matches(args); err != nil {

len(exhausted) will be 1 and len(expected) will be 0

if len(expected)+len(exhausted) == 0 {


if expectedNum == 0 && exhaustedNum == 0 {
fmt.Fprintf(&callsErrors, "there are no expected calls of the method %q for that receiver", method)
} else if exhaustedNum > 0 && callsErrors.Len() == 0 {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is exhaustedNum required? At this point of the function we know we are in error behavior. Are there any other cases where callsErrors.Len() == 0?


if expectedNum == 0 && exhaustedNum == 0 {
fmt.Fprintf(&callsErrors, "there are no expected calls of the method %q for that receiver", method)
} else if exhaustedNum > 0 && callsErrors.Len() == 0 {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think a comment here explaining what error scenario we are handling (i.e. an ordering error) and the rational behind the check for this scenario would be really good.

expectedNum := len(expected)
exhaustedNum := len(exhausted)

if expectedNum == 0 && exhaustedNum == 0 {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this check safe to change? I don't think it is possible for len to ever be less than zero so it seems fine to me.

@cvgw
Copy link
Copy Markdown
Collaborator

cvgw commented Dec 27, 2019

@mjaow are you interested in continuing to work on this PR? If not I'm happy to take it over.

@codyoss
Copy link
Copy Markdown
Member

codyoss commented Feb 22, 2020

Due to lack of response I am closing out this PR for now. I created #404 to track this issue, assigning it to @cvgw for now. Thank you for reporting this.

@codyoss codyoss closed this Feb 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty Error message in Concurrent mode

4 participants