Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/website: sql.Rows example panics. #40664

Closed
feidtmb opened this issue Aug 10, 2020 · 2 comments
Closed

x/website: sql.Rows example panics. #40664

feidtmb opened this issue Aug 10, 2020 · 2 comments
Milestone

Comments

@feidtmb
Copy link

@feidtmb feidtmb commented Aug 10, 2020

What did you do?

Ran the example under the sql.Rows type at https://golang.org/pkg/database/sql/#Rows.Scan.

What did you expect to see?

Logged output from the call:

log.Printf("%s are %d years old", strings.Join(names, ", "), age)
  • (I don't know what's in the database so not sure what exactly the output should be.)

What did you see instead?

A panic:

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

goroutine 1 [running]:
database/sql.(*DB).conn(0x0, 0x0, 0x0, 0x203001, 0xc00006ae38, 0x203000, 0x203000)
	/usr/local/go-faketime/src/database/sql/sql.go:1134 +0x41
database/sql.(*DB).query(0x0, 0x0, 0x0, 0x4f2cf0, 0x22, 0xc00006af38, 0x1, 0x1, 0xc000010201, 0x5aeb00, ...)
	/usr/local/go-faketime/src/database/sql/sql.go:1552 +0x66
database/sql.(*DB).QueryContext(0x0, 0x0, 0x0, 0x4f2cf0, 0x22, 0xc00006af38, 0x1, 0x1, 0xc00006af18, 0x4b474a, ...)
	/usr/local/go-faketime/src/database/sql/sql.go:1534 +0xd1
main.main()
	/tmp/sandbox184082418/prog.go:17 +0xcf

Program exited.
@gopherbot gopherbot added this to the Unreleased milestone Aug 10, 2020
@tpaschalis
Copy link
Contributor

@tpaschalis tpaschalis commented Aug 10, 2020

Right now, I think that all of these examples panic, as the db *sql.DB variable is not initialized anywhere (normally in your code, you'd use something like db, err := sql.Open(...)).

Basically, none of these examples contain //Output comments, so they're probably meant to be compiled and displayed in the documentation, but not to be runnable.

@feidtmb
Copy link
Author

@feidtmb feidtmb commented Aug 10, 2020

Whoops, you're right they do all panic. I dug a little more and found that #9679 already addresses the overall problem (and a comment specifically notes the sql examples), so closing this as a duplicate.

@feidtmb feidtmb closed this Aug 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.