-
Notifications
You must be signed in to change notification settings - Fork 607
source mode error "Loading input failed: loading package failed" #283
Comments
tested using |
I'm not able to use this package with Go modules on. I've tried:
Any suggestions? |
Basically what happens is that when mockgen is executed in a project outside import (
x "."
context "context"
gomock "github.com/golang/mock/gomock"
reflect "reflect"
) Then the compiler complains:
|
Oops, sorry, I'm new to go modules. Once I executed the following commands outside my go module-enabled project, it picked the updated
|
@rgarcia Thanks for reporting this. I'll investigate. |
This seems to be an artifact of golang.org/x/tools/go/packages having more strict rules about where the In the case of your linked script I updated the script: #!/usr/bin/env bash
set -ex
cd /tmp
rm -rf /tmp/mock
mkdir -p /tmp/mock/src/github.com/golang
cd /tmp/mock
export GOPATH=$PWD
pushd src/github.com/golang
git clone https://github.com/golang/mock
(cd mock
git checkout bfa1e97ed7a159b123865559eabdec69b78fe1d5 &&
go build -o /tmp/mock/mockgen-before ./mockgen)
rm -rf mock && git clone https://github.com/golang/mock
(cd mock &&
git checkout 837231f7bb377b365da147e5ff6c031b12f0dfaa &&
go build -o /tmp/mock/mockgen-after ./mockgen)
popd
mkdir -p $GOPATH/src/github.com/bar/foo
cat <<EOF >$GOPATH/src/github.com/bar/foo/interface.go
package foo
type Interface interface {
Bar()
}
EOF
# works
./mockgen-before -package foo -destination interface_mock.go -source $GOPATH/src/github.com/bar/foo/interface.go Interface
# NOW works
if [ "$GO111MODULE" == "on" ]; then
echo "module github.com/bar/foo" > $GOPATH/src/github.com/bar/foo/go.mod
pushd $GOPATH/src/github.com/bar/foo/
/tmp/mock/mockgen-after -package foo -destination interface_mock.go -source interface.go Interface
popd
else
./mockgen-after -package foo -destination interface_mock.go -source $GOPATH/src/github.com/bar/foo/interface.go Interface
fi |
@poy thanks for figuring out the cause! I'm fine closing this for now. Now that I dig into this I think the error message that the script generates is slightly different than the actual error we're seeing at Clever. We build mockgen from a vendor/'d copy pulled down by |
Hello, I'm getting the same error message. To my understanding, this is a bug and still open .. right? |
This problem as experienced by other users turned out to be an error in
their configuration exposed by mockgen becoming more strict about how it
loads files.
Please give us the details of the problem you're experiencing and we can
see what the cause is and whether it requires a fix in mockgen or in your
code.
|
Hello, In any case, thanks for the prompt response! |
Hi, currently I'm getting this error. After execute got this
but if I delete the |
there's a workaround of adding import to mockgen (or other requirement like model), so it will be added to vendor folder. for example adding this to one of test file
|
I just encountered exactly the same error message, and it turned out to be an import cycle issue. |
Please also see fixes and workarounds in #494 |
The commit to switch to go modules (837231f) leads to
mockgen
producing a "Loading input failed" error. I've confirmed that it works with the previous commit, bfa1e97. Repro script: https://gist.github.com/3d0e2b1e77a636851c1f51c10a9a15efGo version is
go version go1.10 linux/amd64
.The text was updated successfully, but these errors were encountered: