-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from teru01/feature/error-logs
improve stack trace logs with %+v
- Loading branch information
Showing
2 changed files
with
21 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"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") | ||
} | ||
return nil | ||
func nestedAction2() error { | ||
return errors.New("fatal error in the nested action2") | ||
} | ||
|
||
func nestedAction() error { | ||
return goerr.Wrap(nestedAction2(), "nestedAction2 failed") | ||
} | ||
|
||
func someAction() error { | ||
return goerr.Wrap(nestedAction(), "nestedAction failed") | ||
} | ||
|
||
func main() { | ||
if err := someAction("no_such_file.txt"); err != nil { | ||
if err := someAction(); err != nil { | ||
log.Fatalf("%+v", err) | ||
} | ||
} |