Either `go doc` confusion or `go mod tidy` confusion

147 views
Skip to first unread message

Kevin Chowski

unread,
Apr 22, 2026, 4:07:54 PM (10 days ago) Apr 22
to golang-nuts
Hey all,

I am a bit confused at what I'm seeing on my system, and I'm hoping someone can reveal what is happening.

I /meant/ to run `go doc http.Handle` but I typed `go doc http.Register` instead. The former works fine, whereas the latter gives me an unexpected error:

```
$ go doc http.Register
doc: go: updates to go.mod needed; to update it:
        go mod tidy
```

If I run `go mod tidy` it doesn't seem like anything happens: `go mod tidy -diff` shows nothing, and my local source control claims my `go.mod` wasn't modified after running `go mod tidy` directly.

Why doesn't `go doc` say something like "there is no Register in package http"? Is it trying to be smart but getting stuck somewhere else?

Nick White

unread,
Apr 22, 2026, 5:29:14 PM (10 days ago) Apr 22
to golan...@googlegroups.com
On Wed, Apr 22, 2026 at 01:07:54PM -0700, Kevin Chowski wrote:
> I /meant/ to run `go doc http.Handle` but I typed `go doc http.Register`
> instead. The former works fine, whereas the latter gives me an unexpected
> error:

I always use the 2 argument form; `go doc http Handle`. That way the
first argument is the package, the second the symbol you're after.
And it has the advantage that if you ask for a symbol that doesn't
exist, you get an error like you were expecting:

```
$ go doc http Register
doc: no symbol Register in package net/http
```

You're right the error message from `go doc http.Register` was
unhelpful, though, that could definitely be improved. I'd encourage
you to open an issue on github for it.

Nick

Kevin Chowski

unread,
Apr 25, 2026, 3:34:25 PM (7 days ago) Apr 25
to golang-nuts
Thanks for the reply, Nick. Unfortunately that command has the same result for me:


$ go doc http Register
doc: go: updates to go.mod needed; to update it:
        go mod tidy

I tried making a minimal reproducer with a freshly init'd go.mod in an empty repository, but I can't reproduce. My guess: go doc is trying to be smart and found some version of some module which has package name http and func name Register, but for some reason it can't be accessed until some change in the go.mod file happens, but that still doesn't match up with the reality that running `go mod tidy` as suggested does nothing.

Perhaps I should file an issue, but I'll need time to actually find a minimal reproducer first - I'm sure this issue is being caused by some strange local code or some other imported module.
Reply all
Reply to author
Forward
0 new messages