-
Notifications
You must be signed in to change notification settings - Fork 267
Mismatch in count, list and graph of imports when some of imports are (currently) invalid. #339
Comments
This appears to happen because Then I visited (and therefore indexed) http://localhost:8080/github.com/samuel/go-zookeeper/zk, afterwards: |
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". |
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. |
In the "Package foo imports 3 packages (graph)." sentence, the number of packages is being calculated from the
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, |
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:
Yet when you click that link, only 2 packages (the valid ones) are listed:
https://godoc.org/gist.github.com/3ccb35092336d9362883.git?imports
The graph view shows all imports:
https://godoc.org/gist.github.com/3ccb35092336d9362883.git?import-graph&hide=1
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.
The text was updated successfully, but these errors were encountered: