2024-10-12 02:11:43 +09:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2024-12-20 00:20:02 +09:00
|
|
|
"git.gensokyo.uk/security/fortify/internal/app"
|
|
|
|
"git.gensokyo.uk/security/fortify/internal/fmsg"
|
2024-10-12 02:11:43 +09:00
|
|
|
)
|
|
|
|
|
|
|
|
func logWaitError(err error) {
|
2024-10-16 01:38:59 +09:00
|
|
|
var e *fmsg.BaseError
|
|
|
|
if !fmsg.AsBaseError(err, &e) {
|
2024-10-21 20:47:02 +09:00
|
|
|
fmsg.Println("wait failed:", err)
|
2024-10-12 02:11:43 +09:00
|
|
|
} 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
|
2024-10-21 20:47:02 +09:00
|
|
|
fmsg.Print(e.Message())
|
2024-10-12 02:11:43 +09:00
|
|
|
} else {
|
|
|
|
// inner error are either unwrapped store errors
|
|
|
|
// or joined errors returned by *appSealTx revert
|
|
|
|
// wrapped in *app.BaseError
|
|
|
|
var ej app.RevertCompoundError
|
|
|
|
if !errors.As(se.InnerErr, &ej) {
|
|
|
|
// does not require special handling
|
2024-10-21 20:47:02 +09:00
|
|
|
fmsg.Print(e.Message())
|
2024-10-12 02:11:43 +09:00
|
|
|
} else {
|
|
|
|
errs := ej.Unwrap()
|
|
|
|
|
|
|
|
// every error here is wrapped in *app.BaseError
|
|
|
|
for _, ei := range errs {
|
2024-10-16 01:38:59 +09:00
|
|
|
var eb *fmsg.BaseError
|
2024-10-12 02:11:43 +09:00
|
|
|
if !errors.As(ei, &eb) {
|
|
|
|
// unreachable
|
2024-10-21 20:47:02 +09:00
|
|
|
fmsg.Println("invalid error type returned by revert:", ei)
|
2024-10-12 02:11:43 +09:00
|
|
|
} else {
|
|
|
|
// print inner *app.BaseError message
|
2024-10-21 20:47:02 +09:00
|
|
|
fmsg.Print(eb.Message())
|
2024-10-12 02:11:43 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func logBaseError(err error, message string) {
|
2024-10-16 01:38:59 +09:00
|
|
|
var e *fmsg.BaseError
|
2024-10-12 02:11:43 +09:00
|
|
|
|
2024-10-16 01:38:59 +09:00
|
|
|
if fmsg.AsBaseError(err, &e) {
|
2024-10-21 20:47:02 +09:00
|
|
|
fmsg.Print(e.Message())
|
2024-10-12 02:11:43 +09:00
|
|
|
} else {
|
2024-10-26 23:09:32 +09:00
|
|
|
fmsg.Println(message, err)
|
2024-10-12 02:11:43 +09:00
|
|
|
}
|
|
|
|
}
|