mirror of
https://gitea.com/gitea/tea.git
synced 2025-09-02 09:58:29 +02:00
Refactor error handling (#308)
use fmt instead of log log.Fatal -> return err set non-zero exit code on error print to default err log cleanup fix vet Co-authored-by: Norwin Roosen <git@nroo.de> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/308 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: 6543 <6543@obermui.de> Co-Authored-By: Norwin <noerw@noreply.gitea.io> Co-Committed-By: Norwin <noerw@noreply.gitea.io>
This commit is contained in:
@ -6,7 +6,6 @@ package releases
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -76,24 +75,23 @@ func runReleaseCreate(cmd *cli.Context) error {
|
||||
|
||||
if err != nil {
|
||||
if resp != nil && resp.StatusCode == http.StatusConflict {
|
||||
fmt.Println("error: There already is a release for this tag")
|
||||
return nil
|
||||
return fmt.Errorf("There already is a release for this tag")
|
||||
}
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
for _, asset := range ctx.StringSlice("asset") {
|
||||
var file *os.File
|
||||
|
||||
if file, err = os.Open(asset); err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
filePath := filepath.Base(asset)
|
||||
|
||||
if _, _, err = ctx.Login.Client().CreateReleaseAttachment(ctx.Owner, ctx.Repo, release.ID, file, filePath); err != nil {
|
||||
file.Close()
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
file.Close()
|
||||
|
@ -6,7 +6,6 @@ package releases
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
@ -38,7 +37,7 @@ func RunReleasesList(cmd *cli.Context) error {
|
||||
ListOptions: ctx.GetListOptions(),
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
print.ReleasesList(releases, ctx.Output)
|
||||
|
Reference in New Issue
Block a user