bud: bud run fails right after adding controller following video

error message:

| genfs: open "bud/internal/web/web.go". genfs: open "bud/internal/web/controller/controller.go". framework/controller: unable to load. controller: unable to load: di: unable to wire "change.me/bud/controller".loadController function. parser: unable to find import path for "hackernews" in "controller/controller.go"

my go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/piotr/.cache/go-build"
GOENV="/home/piotr/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/piotr/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/piotr/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.5"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/piotr/WORK/mysiar/go/hacker-news/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3793912841=/tmp/go-build -gno-record-gcc-switches"

any suggestion ho to solve it is more than welcome

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 18 (9 by maintainers)

Most upvoted comments

Thanks for testing! I guess build.Package doesn’t actually resolve symlinks.

I was able to reproduce this in a Docker container. Could you check if this is working as expected?

diff --git a/package/gomod/module.go b/package/gomod/module.go
index c6d90c6..c573626 100644
--- a/package/gomod/module.go
+++ b/package/gomod/module.go
@@ -91,12 +91,23 @@ func (m *Module) ReadDir(name string) ([]fs.DirEntry, error) {
 }
 
 // ResolveImport returns an import path from a local directory.
-func (m *Module) ResolveImport(directory string) (importPath string, err error) {
-       relPath, err := filepath.Rel(m.dir, filepath.Clean(directory))
+func (m *Module) ResolveImport(dir string) (importPath string, err error) {
+       return m.resolveImport(dir, true)
+}
+
+func (m *Module) resolveImport(dir string, evalSymlinks bool) (string, error) {
+       relPath, err := filepath.Rel(m.dir, dir)
        if err != nil {
                return "", err
        } else if strings.HasPrefix(relPath, "..") {
-               return "", fmt.Errorf("%q can't be outside the module directory %q", directory, m.dir)
+               if !evalSymlinks {
+                       return "", fmt.Errorf("module: unable to resolve import. %q can't be outside the module directory %q", dir, m.dir)
+               }
+               // Maybe the directory is a symlink, resolve that symlink and try again.
+               if dir, err = filepath.EvalSymlinks(dir); err != nil {
+                       return "", fmt.Errorf("module: unable to resolve import for %q. %w", dir, err)
+               }
+               return m.resolveImport(dir, false)
        }
        return m.Import(relPath), nil
 }

@matthewmueller

I think i found the “problem”

under Ubuntu 22.04 , Golang is installed under /usr/share/go-1.1x, and some symbolic links are created under /usr/lib/go-1.1x

image

mod will translate the symbolic links to real path https://github.com/livebud/bud/blob/061c0f135037f65d3ed7ee16671d79052d29f0b4/package/gomod/mod.go#L158

that’s why /usr/lib/go-1.19 became /usr/share/go-1.19

@matthewmueller

i’ll have a try to find the problem

btw: should we start a new issue?