Skip to the content ForoHackers
Log inJoin

My Go function returns a nil pointer and my caller is having a perfectly non-nil panic about it

DebuggingGoLanguage design
#16052 · · Quote · Report

not an actual panic, that's my manager. worker returned an error on an empty queue. I expected nil. my local var p *Jam is nil. jam implements error on its pointer receiver. function returns p as error and the caller takes the failure branch. can I go home with the pointer and leave the interface here?

#16248 · · Quote · Report

Print p == nil, err == nil and the dynamic type of err. Three separate, boring questions. I'd like the boring answers before someone proposes a framework.

#16249 · · Quote · Report

true, false, *main.Jam. christ. it has retained a very accurate description of the kind of nothing I sent it.

#16250 · · Quote · Report

Your interface contains a type and a value. Here the value is a nil *Jam, but the type is present. Return nil directly in the success case. Then you can move on to fighting whatever's actually in the queue.

#16251 · · Quote · Report

did we just spend four salaries and a packet of biscuits on a decision between nil Deluxe and regular nil

#16256 · · Quote · Report

test now does both: empty queue gives nil, deliberately jammed toy queue gives a *Jam. no failure alert from an empty queue overnight. got to talk to the manager about an actual broken job this morning. mixed feelings about progress.

You are not logged in, so this goes up anonymously: no account, no name and no address is stored with it, and it may carry no link and no image. Log in or join to post under your name. Our web server's logs keep the address and time of every request for up to 14 days; to keep yours out of them, use Tor. To reach the staff in confidence, use the drop. Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply