Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Got '*pkgtree.NonCanonicalImportRoot' error when porting to dep #1742

Closed
twang2218 opened this issue Mar 8, 2018 · 4 comments · Fixed by #1743
Closed

Got '*pkgtree.NonCanonicalImportRoot' error when porting to dep #1742

twang2218 opened this issue Mar 8, 2018 · 4 comments · Fixed by #1743

Comments

@twang2218
Copy link
Contributor

What version of dep are you using (dep version)?

$ dep version
dep:
 version     : v0.4.1
 build date  : 2018-01-27
 git hash    : 37d9ea0
 go version  : go1.9.3
 go compiler : gc
 platform    : darwin/amd64

What dep command did you run?

$ dep init -v
...
(30)  ? attempt github.com/megamsys/go-radosgw with 1 pkgs; at least 1 versions to try
(30)      try github.com/megamsys/go-radosgw@master
(31)  ✗   github.com/megamsys/go-radosgw at master has problem subpkg(s):
(31)            github.com/megamsys/go-radosgw/api has err (*pkgtree.NonCanonicalImportRoot); required by (root).
(30)    ← no more versions of github.com/megamsys/go-radosgw to try; begin backtrack

...

  ✗ solving failed

Solver wall times by segment:
     b-source-exists:  45.62367537s
         b-list-pkgs: 10.186192761s
              b-gmal:  7.940766056s
  b-deduce-proj-root:  579.123944ms
             satisfy:   18.612194ms
            unselect:   15.306904ms
         select-atom:   14.825777ms
         select-root:    2.995456ms
            new-atom:    1.737909ms
           backtrack:     428.235µs
               other:     202.533µs
     b-list-versions:      19.078µs

  TOTAL: 1m4.383886217s

init failed: unable to solve the dependency graph: Solving failure: No versions of github.com/megamsys/go-radosgw met constraints:
        master: Could not introduce github.com/megamsys/go-radosgw@master, as its subpackage github.com/megamsys/go-radosgw/api does not contain usable Go code (*pkgtree.NonCanonicalImportRoot).. (Package is required by (root).)

After I examine the package github.com/megamsys/go-radosgw/api, I found one potential reason caused this error, https://github.com/megamsys/go-radosgw/blob/master/api/helpers_test.go#L3:

package radosAPI
/*
import (
	"os"
	"testing"
	"time"
	. "github.com/smartystreets/goconvey/convey"
)

...

And then I checked the gps/pkgtree/pkgtree.go's findImportComment() function, I think it might be a bug:

https://github.com/golang/dep/blob/master/gps/pkgtree/pkgtree.go#L344-L362

	case bytes.HasPrefix(text, slashStar):
		text = text[2:]
		end := bytes.Index(text, starSlash)
		if end < 0 {
			// malformed comment
			return ""
		}
		text = text[:end]
		if bytes.IndexByte(text, '\n') > 0 {
			// multiline comment, can't be an import comment
			return ""
		}
	}
	text = bytes.TrimSpace(text)
	if !bytes.HasPrefix(text, importKwd) {
		return ""
	}
	quotedPath := bytes.TrimSpace(text[len(importKwd):])
	return string(bytes.Trim(quotedPath, `"`))

I think:

		if bytes.IndexByte(text, '\n') > 0 {

should be

		if bytes.IndexByte(text, '\n') >= 0 {
@twang2218
Copy link
Contributor Author

twang2218 commented Mar 8, 2018

I compiled the dep using master branch, and added println() to print the Error details, and here is what I found:

import root "github.com/megamsys/go-radosgw" is not a prefix for the package's declared canonical path "(\n\t\"os\"\n\t\"testing\"\n\t\"time\"\n\n\t. \"github.com/smartystreets/goconvey/convey\"\n)\n\nfunc TestNewAPI(t *testing.T) {\n\tConvey(\"Testing New API\", t, func() {\n\t\tapi := New(os.Getenv(\"RADOSGW_API\"), os.Getenv(\"RADOSGW_ACCESS\"), os.Getenv(\"RADOSGW_SECRET\"))\n\n\t\tSo(api, ShouldNotBeNil)\n\t})\n}\n\nfunc TestNewAPIWithPrefix(t *testing.T) ...

I think it clearly shows the comments have become the canonical path.

@twang2218
Copy link
Contributor Author

Created a PR #1743 to fix this issue.

twang2218 added a commit to virtengine/whmcs_go that referenced this issue Mar 13, 2018
Signed-off-by: Tao Wang <twang2218@gmail.com>
twang2218 added a commit to virtengine/opennebula-go that referenced this issue Mar 13, 2018
Signed-off-by: Tao Wang <twang2218@gmail.com>
@twang2218
Copy link
Contributor Author

Found a workaround for this issue.

Replace:

/*
import (
    "fmt"
)
...
*/

with

/**
import (
    "fmt"
)
...
*/

Use the double star, /**, then dep will not treat the following comments as the import path.

twang2218 added a commit to virtengine/ve-vertice-v1 that referenced this issue Mar 14, 2018
* Replace '/* import' with '/** import' to workaround golang/dep#1742.

Signed-off-by: Tao Wang <twang2218@gmail.com>
fabrice102 added a commit to fabrice102/amcl that referenced this issue Apr 6, 2018
hueys pushed a commit to hueys/go-timecode that referenced this issue May 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
@twang2218 and others