diff options
| author | Ophestra Umiker <cat@ophivana.moe> | 2024-10-21 20:47:02 +0900 |
|---|---|---|
| committer | Ophestra Umiker <cat@ophivana.moe> | 2024-10-21 20:47:02 +0900 |
| commit | 42e0b168e3d75389dfb968aebf9f5629d64782f9 (patch) | |
| tree | e6b430205213c62bc06275c6d84e6037d40f5c3f /error.go | |
| parent | 380d1f45851b7dffb963c51da96a17ba41f3cfb8 (diff) | |
fmsg: produce all output through fmsg
The behaviour of print functions from package fmt is not thread safe. Functions provided by fmsg wrap around Logger methods. This makes prefix much cleaner and makes it easy to deal with future changes to logging.
Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'error.go')
| -rw-r--r-- | error.go | 18 |
1 files changed, 6 insertions, 12 deletions
@@ -3,7 +3,6 @@ package main import ( "errors" "fmt" - "os" "git.ophivana.moe/security/fortify/internal/app" "git.ophivana.moe/security/fortify/internal/fmsg" @@ -12,13 +11,13 @@ import ( func logWaitError(err error) { var e *fmsg.BaseError if !fmsg.AsBaseError(err, &e) { - fmt.Println("fortify: wait failed:", err) + fmsg.Println("wait failed:", err) } else { // Wait only returns either *app.ProcessError or *app.StateStoreError wrapped in a *app.BaseError var se *app.StateStoreError if !errors.As(err, &se) { // does not need special handling - fmt.Print("fortify: " + e.Message()) + fmsg.Print(e.Message()) } else { // inner error are either unwrapped store errors // or joined errors returned by *appSealTx revert @@ -26,7 +25,7 @@ func logWaitError(err error) { var ej app.RevertCompoundError if !errors.As(se.InnerErr, &ej) { // does not require special handling - fmt.Print("fortify: " + e.Message()) + fmsg.Print(e.Message()) } else { errs := ej.Unwrap() @@ -35,10 +34,10 @@ func logWaitError(err error) { var eb *fmsg.BaseError if !errors.As(ei, &eb) { // unreachable - fmt.Println("fortify: invalid error type returned by revert:", ei) + fmsg.Println("invalid error type returned by revert:", ei) } else { // print inner *app.BaseError message - fmt.Print("fortify: " + eb.Message()) + fmsg.Print(eb.Message()) } } } @@ -50,13 +49,8 @@ func logBaseError(err error, message string) { var e *fmsg.BaseError if fmsg.AsBaseError(err, &e) { - fmt.Print("fortify: " + e.Message()) + fmsg.Print(e.Message()) } else { fmt.Println(message, err) } } - -func fatalf(format string, a ...any) { - fmt.Printf("fortify: "+format, a...) - os.Exit(1) -} |
