Hey all, my team has been experimenting with pulum...
# getting-started
s
Hey all, my team has been experimenting with pulumi for a few months, and I'm running into an issue with tracking down errors. We are use Go as our language, and bubbling up the errors using
return
, as is pretty common in Go. When the resource fail for whatever reason, it's hard to track down in the codebase where athey are happening. Are there are tricks to doing this? I've tried using something like https://github.com/pkg/errors, or even hand-rolling our own error with a callstack, but that hasn't deemed super successful. I'm hesitant to use
panic
everywhere, though that may be more helpful as I will know where the errors are occurring. Any advice on error handling in go to make it easier to track down where issues are happening? Thanks!
p
I am using github.com/pkg/errors and always do something like:
Copy code
if err != nil {
	return errors.Wrapf(err, "message with error context goes here")
}
It is not bad and I usually can track down any error. But I must say I don't like it.
s
so you can track it by using that message you provide?
g
You have many options here and if you don't provide addition context when encountering an error I understand how that feels hard. I typically write a func to handle errors generally. Use ctx.Log.Error(err.Error()) with some nice text to help yourself. Golang is the choice here introducing this friction as it forces you to handle your errors. Here is no exception, I really prefer this honestly. If there is an error you want it to fail fast just call os.Exit(1) to stop before.moving further.
p
@some-grass-63999 The message yes, but there is something better. Try this:
Copy code
func main() {

	err := errors.New("something very bad happened")

	err = errors.Wrap(err, "even worse")

	err = errors.Wrap(err, "bad bad")

	fmt.Printf("%+v", err)
}
(note
"%+v"
)
experimenting a little bit more:
Copy code
func main() {
	err := func1()

	fmt.Printf("%+v", err)
}

func func1() error {
	return func2()
}

func func2() error {
	return errors.New("something very bad happened")
}
this one also prints the call stack