Skip to content

Commit

Permalink
fix the example
Browse files Browse the repository at this point in the history
  • Loading branch information
teru01 committed May 12, 2024
1 parent f8d77fe commit 1b43fe7
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions examples/stacktrace_print/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@ package main

import (
"log"
"os"

"github.com/m-mizutani/goerr"
)

func someAction(fname string) error {
if _, err := os.Open(fname); err != nil {
return goerr.Wrap(err, "failed to open file")
func nestedAction2() error {
return goerr.New("fatal error in the nested action2")
}

func nestedAction() error {
return goerr.Wrap(nestedAction2(), "nestedAction2 failed")
}

func someAction() error {
if err := nestedAction(); err != nil {
return goerr.Wrap(err, "nestedAction failed")
}
return nil
}

func main() {
if err := someAction("no_such_file.txt"); err != nil {
if err := someAction(); err != nil {
log.Fatalf("%+v", err)
}
}

0 comments on commit 1b43fe7

Please sign in to comment.