From 1b43fe7277573d167bd6bfd6d5e918b1f9c371c3 Mon Sep 17 00:00:00 2001 From: ono-teruya <27873650+teru01@users.noreply.github.com> Date: Sun, 12 May 2024 16:35:49 +0900 Subject: [PATCH] fix the example --- examples/stacktrace_print/main.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/examples/stacktrace_print/main.go b/examples/stacktrace_print/main.go index 3ffb419..e099dea 100644 --- a/examples/stacktrace_print/main.go +++ b/examples/stacktrace_print/main.go @@ -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) } }