Skip to content

x/pkgsite: Code Block should show line numbers #56372

Open
@valaparthvi

Description

@valaparthvi

What is the URL of the page with the issue?

Example: https://pkg.go.dev/golang.org/x/sync/errgroup#Group.Wait

What is your user agent?

Mozilla/5.0 (X11; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0

Screenshot

Screenshot from 2022-10-21 17-52-28

What did you do?

Modify the example code, in this case, it was a bad code and panicked.

package main

import (
	"fmt"
	"net/http"

	"golang.org/x/sync/errgroup"
)

func main() {
	g := new(errgroup.Group)
	var urls = []string{
		"http://www.golang.org/",
		"http://www.google.com/",
		"http://www.somestupidname.com/",
	}
	for _, url := range urls {
		// Launch a goroutine to fetch the URL.
		url := url // https://golang.org/doc/faq#closures_and_goroutines
		g.Go(func() error {
			// Fetch the URL.
			resp, err := http.Get(url)
			if err != nil {
				fmt.Println("error encountered")
				resp.Body.Close()
				return nil
			}
			fmt.Println("ignoring error if any")
			resp.Body.Close()
			return nil
		})
	}
	// Wait for all HTTP fetches to complete.
	if err := g.Wait(); err == nil {
		fmt.Println("Successfully fetched all URLs.")
	}
}

What did you expect to see?

Error message

Output:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x61cb7a]

goroutine 7 [running]:
main.main.func1()
	/tmp/sandbox1760300329/prog.go:25 +0x7a
golang.org/x/sync/errgroup.(*Group).Go.func1()
	/tmp/gopath4274196458/pkg/mod/golang.org/x/sync@v0.1.0/errgroup/errgroup.go:75 +0x64
created by golang.org/x/sync/errgroup.(*Group).Go
	/tmp/gopath4274196458/pkg/mod/golang.org/x/sync@v0.1.0/errgroup/errgroup.go:72 +0xa5

It tells the line on which error occurred. But the code is not numbered, and hence it is difficult to determine the code line that threw error.

It would be helpful if the code blocks were numbered.

What did you see instead?

Metadata

Metadata

Assignees

Labels

NeedsFixThe path to resolution is known, but the work has not been done.pkgsite

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions