Skip to content
This repository has been archived by the owner on Jan 16, 2021. It is now read-only.

Mismatch in count, list and graph of imports when some of imports are (currently) invalid. #339

Closed
dmitshur opened this issue Oct 17, 2015 · 4 comments

Comments

@dmitshur
Copy link
Contributor

Due to packages moving, being renamed, or deleted, sometimes there are Go packages that import invalid or non-existent Go packages. Such code would not compile (unless you have vendored dependencies, etc.), but its documentation can and is still displayed by godoc.org.

However, when a Go package imports an invalid import path, there is an inconsistency between the number of imports, the list of imports, and the graph of imports.

Reproduce case:

https://godoc.org/gist.github.com/3ccb35092336d9362883.git

It imports a total of 3 Go packages. Two valid Go packages and one invalid one (it's a folder that contains no .go files). It would fail to compile. However, notice that:

image

Yet when you click that link, only 2 packages (the valid ones) are listed:

https://godoc.org/gist.github.com/3ccb35092336d9362883.git?imports

image

The graph view shows all imports:

https://godoc.org/gist.github.com/3ccb35092336d9362883.git?import-graph&hide=1

image

Since godoc.org doesn't check if Go packages compile, it shouldn't try to hide them. I am guessing it's an unintended bug.

Pretty minor issue, reporting because I noticed it.

Edit: Unfortunately, I deleted the original gist that was used to demonstrate the issue because I forgot what it was needed for. So I've re-created another one that reproduces the issue and updated links above. It works equally well.

@dmitshur
Copy link
Contributor Author

This appears to happen because github.com/samuel/go-zookeeper is a valid Go repo, but the folder contains no Go files. Before the repo is indexed, this bug does not occur. Here's a screenshot from a local gddo-server instance before I visited and indexed go-zookeeper:

image

Then I visited (and therefore indexed) http://localhost:8080/github.com/samuel/go-zookeeper/zk, afterwards:

image

@dmitshur
Copy link
Contributor Author

The problem is not in the templates (rendering step) like I thought, it's in the database. Some logic results in the database not having all of its imports.

pkgs, err = db.Packages(pdoc.Imports)
if err != nil {
    return err
}

That results in just 2 packages, "fmt" and "net".

@dmitshur
Copy link
Contributor Author

I'll probably stop investigating here because it's not a critical issue and fixing it would require me to get more familiar with the database, crawling, etc., logic. Someone who's interested or more familiar can take over if they want.

@dmitshur
Copy link
Contributor Author

In the "Package foo imports 3 packages (graph)." sentence, the number of packages is being calculated from the *doc.Package rather than accessing the database:

{{.Imports|len}}

So, a quick hacky solution (a bandaid rather than fixing it at the root) would be, FWIW:

diff --git a/gddo-server/main.go b/gddo-server/main.go
index 816971a..8a10a50 100644
--- a/gddo-server/main.go
+++ b/gddo-server/main.go
@@ -321,6 +321,9 @@ func servePackage(resp http.ResponseWriter, req *http.Request) error {
        if err != nil {
            return err
        }
+       if len(pdoc.Imports) > len(pkgs) {
+           // Add missing imports to pkgs.
+       }
        return executeTemplate(resp, "imports.html", http.StatusOK, nil, map[string]interface{}{
            "flashMessages": flashMessages,
            "pkgs":          pkgs,

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant