go podcast()

001: Error handling in Go


Listen Later

  • 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.

...more
View all episodesView all episodes
Download on the App Store

go podcast()By Dominic St-Pierre

  • 3.8
  • 3.8
  • 3.8
  • 3.8
  • 3.8

3.8

6 ratings


More shows like go podcast()

View all
Cup o' Go by Jonathan Hall & Shay Nehmad

Cup o' Go

16 Listeners