mirror of
https://github.com/iyear/tdl
synced 2025-01-05 10:27:16 +08:00
feat(main): humanize some errors
This commit is contained in:
parent
a77e9d6d81
commit
296d9285de
15
main.go
15
main.go
@ -5,7 +5,10 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
|
||||
surveyterm "github.com/AlecAivazis/survey/v2/terminal"
|
||||
"github.com/fatih/color"
|
||||
"github.com/go-faster/errors"
|
||||
"go.etcd.io/bbolt"
|
||||
|
||||
"github.com/iyear/tdl/cmd"
|
||||
)
|
||||
@ -14,7 +17,19 @@ func main() {
|
||||
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
||||
defer cancel()
|
||||
|
||||
humanizeErrors := map[error]string{
|
||||
bbolt.ErrTimeout: "Current database is used by another process, please terminate it first",
|
||||
surveyterm.InterruptErr: "Interrupted",
|
||||
}
|
||||
|
||||
if err := cmd.New().ExecuteContext(ctx); err != nil {
|
||||
for e, m := range humanizeErrors {
|
||||
if errors.Is(err, e) {
|
||||
color.Red("%s", m)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
color.Red("Error: %+v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user