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

mockery v2.10.0 cannot generate file on go1.18 #434

Closed
ilovejs opened this issue Mar 15, 2022 · 9 comments
Closed

mockery v2.10.0 cannot generate file on go1.18 #434

ilovejs opened this issue Mar 15, 2022 · 9 comments

Comments

@ilovejs
Copy link

ilovejs commented Mar 15, 2022

How to reproduce

mockery version: v2.10.0
env: go 1.18
demo repo: https://github.com/sgreben/testing-with-gomock
output:
❯ mockery --dir=doer --name=Doer
16 Mar 22 10:48 AEDT INF Starting mockery dry-run=false version=v2.10.0
16 Mar 22 10:48 AEDT INF Walking dry-run=false version=v2.10.0
16 Mar 22 10:48 AEDT FTL Unable to find 'Doer' in any go files under this path dry-run=false version=v2.10.0

cd doer
❯ mockery --all
16 Mar 22 10:49 AEDT INF Starting mockery dry-run=false version=v2.10.0
16 Mar 22 10:49 AEDT INF Walking dry-run=false version=v2.10.0
❯ ls
doer.go

Other bugs

in a larger private repo, internal error
2022/03/16 10:50:38 internal error: package "net/http" without types was imported from "xxx"

Possible reason

when downgrade to go1.16.15 it works for my larger scale project but failed on that demo repo up there
so it's a positive feedback

@ilovejs ilovejs changed the title cannot generate file on go1.18 mockery v2.10.0 cannot generate file on go1.18 Mar 15, 2022
@taylow
Copy link

taylow commented Mar 16, 2022

Having the same issue with 1.18 internal error: package "fmt" without types was imported from ...

@jcobhams
Copy link

Having similar issue with the error message
invalid operation: ctx.Value(some_key) (value with invalid type) is not an interface" dry-run=false version=v2.9.4

Go Version: 1.18

@yanghp
Copy link

yanghp commented Mar 17, 2022

yes, Having the same issue with 1.18 internal error: package "context" without types was imported from ....
running "mockery": exit status 1

@yanghp
Copy link

yanghp commented Mar 17, 2022

update to mockery version: v2.10.0 is ok

@emmanuel099
Copy link
Contributor

Having a similar issue with Go 1.18: Unexpected package creation during export data loading

Adding packages.NeedDeps flag to packages config in parse.go fixes the problem. Similar fix has been applied to gqlgen (see 99designs/gqlgen#1961).

emmanuel099 added a commit to emmanuel099/mockery that referenced this issue Mar 17, 2022
Without the additional `NeedDeps` mockery fails with:
"Unexpected package creation during export data loading"

Refs vektra#434
@dillonstreator
Copy link
Contributor

Has similar issue with system version overriding user version of mockery

which mockery
/usr/local/bin/mockery
rm /usr/local/bin/mockery
go install github.com/vektra/mockery/v2@latest
which mockery
/Users/{username}/go/bin/mockery

mockery worked again after running this

@cfstras
Copy link
Contributor

cfstras commented Mar 23, 2022

This is a bit confusing... The binary downloaded from https://github.com/vektra/mockery/releases/tag/v2.10.0 (darwin_arm64) reports an error:

➜  ~/Downloads/mockery_2.10.0_Darwin_arm64/mockery --name Client
23 Mar 22 09:35 CET INF Starting mockery dry-run=false version=v2.10.0
23 Mar 22 09:35 CET INF Walking dry-run=false version=v2.10.0
2022/03/23 09:35:59 internal error: package "net/http" without types was imported from "<snip>"

But running go install manually works:

➜ go install github.com/vektra/mockery/v2@v2.10.0

➜ $GOBIN/mockery --name Client
23 Mar 22 09:37 CET INF Starting mockery dry-run=false version=v2.10.0
23 Mar 22 09:37 CET INF Walking dry-run=false version=v2.10.0
23 Mar 22 09:37 CET INF Generating mock dry-run=false interface=Client qualified-name=<snip> version=v2.10.0

Both report the same version, was the release built from the wrong tag?

@atombender
Copy link
Contributor

The release is presumably built with Go 1.17, while go install builds it using your local Go 1.18.

@cfstras
Copy link
Contributor

cfstras commented Mar 31, 2022

Sadly 1.10.1 does not fix this issue. The release 2.10.1 seems to be built with go 1.16.14:

➜ go version -m ~/Downloads/mockery_2.10.1_Darwin_arm64/mockery
/Users/claus/Downloads/mockery_2.10.1_Darwin_arm64/mockery: go1.16.14
...

Running mockery in a folder with this simple test file does not work:

package tmp
import "sync"
func stuff() {
	var m sync.Map
	m.Range(func(key interface{}, value interface{}) bool {
		return false
	})
}
~/Downloads/mockery_2.10.1_Darwin_arm64/mockery --all
31 Mar 22 10:51 CEST INF Starting mockery dry-run=false version=v2.10.1
31 Mar 22 10:51 CEST INF Walking dry-run=false version=v2.10.1
31 Mar 22 10:51 CEST ERR Error parsing file error="/Users/claus/ext_src/mockery/tmp/test.go:7:10: cannot use (func(key interface{}, value interface{}) bool literal) (value of type func(key interface{}, value interface{}) bool) as func(key invalid type, value invalid type) bool value in argument to m.Range" dry-run=false version=v2.10.1

While running a version manually built with go1.18 works:

➜ go version -m ../mockery
../mockery: go1.18
...
➜ ../mockery --all
31 Mar 22 10:51 CEST INF Starting mockery dry-run=false version=v0.0.0-dev
31 Mar 22 10:51 CEST INF Walking dry-run=false version=v0.0.0-dev
# (Exits with code 0)

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

No branches or pull requests

9 participants