From 2bdd72dfff2db45fc4e5b2613838375cd5128301 Mon Sep 17 00:00:00 2001 From: Norwin Date: Sat, 3 Jul 2021 22:39:05 +0800 Subject: [PATCH] Improve error messages (#370) fixes #367 Co-authored-by: Norwin Roosen Co-authored-by: Lunny Xiao Reviewed-on: https://gitea.com/gitea/tea/pulls/370 Reviewed-by: 6543 <6543@obermui.de> Reviewed-by: KN4CK3R Co-authored-by: Norwin Co-committed-by: Norwin --- modules/context/context.go | 10 +++++++++- modules/task/pull_checkout.go | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/context/context.go b/modules/context/context.go index cf5eb7d..fc7a7b4 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -123,8 +123,16 @@ func InitCommand(ctx *cli.Context) *TeaContext { } } else if c.Login == nil { if c.Login, err = config.GetDefaultLogin(); err != nil { - log.Fatal(err.Error()) + if err.Error() == "No available login" { + // TODO: maybe we can directly start interact.CreateLogin() (only if + // we're sure we can interactively!), as gh cli does. + fmt.Println(`No gitea login configured. To start using tea, first run + tea login add +and then run your command again.`) + } + os.Exit(1) } + fmt.Printf("NOTE: no gitea login detected, falling back to login '%s'\n", c.Login.Name) } // parse reposlug (owner falling back to login owner if reposlug contains only repo name) diff --git a/modules/task/pull_checkout.go b/modules/task/pull_checkout.go index 9beceaa..a003982 100644 --- a/modules/task/pull_checkout.go +++ b/modules/task/pull_checkout.go @@ -28,7 +28,7 @@ func PullCheckout( client := login.Client() pr, _, err := client.GetPullRequest(repoOwner, repoName, index) if err != nil { - return err + return fmt.Errorf("couldn't fetch PR: %s", err) } if err := workaround.FixPullHeadSha(client, pr); err != nil { return err