
Episode 1
001: Error handling in Go
I talk about error handling in Go, why I think it's good but after a little bit of time getting used to have error as values.
January 10, 202216m 44s
Audio is streamed directly from the publisher (media.transistor.fm) as published in their RSS feed. Play Podcasts does not host this file. Rights-holders can request removal through the copyright & takedown page.
Show Notes
- Wrapping error: fmt.Errorf("error trying to do X: %w", err)
- Package errors: https://pkg.go.dev/errors
Example of not using the happy path at 1st indentation:
try {if (user.HasAccessTo(Admin) {
if (somethingElse()) {
// happy path
}
else {}
}
else {}
}
catch(Exception ex) {
// what really happened, and where?
}
An example of happy path in idiomatic Go:
ok, error := hasAccessTo(user, ADMIN)if err != nil || !ok {
// handle not access
}
if !somethingElse() {
// handle something else false
}
// Happy path
My course on building SaaS apps in Go.
Topics
gogolangprogrammingcodedeveloper