Dont panic, report error back (#582)

dont panic! return error back
This commit is contained in:
6543
2021-12-08 23:36:23 +01:00
committed by GitHub
parent 0061edcbe2
commit 3ec00140d9
4 changed files with 50 additions and 18 deletions
+17 -4
View File
@@ -74,7 +74,10 @@ func GetBuild(c *gin.Context) {
}
files, _ := _store.FileList(build)
procs, _ := _store.ProcList(build)
build.Procs = model.Tree(procs)
if build.Procs, err = model.Tree(procs); err != nil {
_ = c.AbortWithError(http.StatusInternalServerError, err)
return
}
build.Files = files
c.JSON(http.StatusOK, build)
@@ -91,8 +94,15 @@ func GetBuildLast(c *gin.Context) {
return
}
procs, _ := _store.ProcList(build)
build.Procs = model.Tree(procs)
procs, err := _store.ProcList(build)
if err != nil {
_ = c.AbortWithError(http.StatusInternalServerError, err)
return
}
if build.Procs, err = model.Tree(procs); err != nil {
_ = c.AbortWithError(http.StatusInternalServerError, err)
return
}
c.JSON(http.StatusOK, build)
}
@@ -250,7 +260,10 @@ func DeleteBuild(c *gin.Context) {
_ = c.AbortWithError(404, err)
return
}
killedBuild.Procs = model.Tree(procs)
if killedBuild.Procs, err = model.Tree(procs); err != nil {
_ = c.AbortWithError(http.StatusInternalServerError, err)
return
}
if err := publishToTopic(c, killedBuild, repo, model.Canceled); err != nil {
log.Error().Err(err).Msg("publishToTopic")
}
+5 -2
View File
@@ -371,7 +371,7 @@ func findOrPersistPipelineConfig(repo *model.Repo, build *model.Build, remoteYam
}
// publishes message to UI clients
func publishToTopic(c *gin.Context, build *model.Build, repo *model.Repo, event model.EventType) error {
func publishToTopic(c *gin.Context, build *model.Build, repo *model.Repo, event model.EventType) (err error) {
message := pubsub.Message{
Labels: map[string]string{
"repo": repo.FullName,
@@ -379,7 +379,10 @@ func publishToTopic(c *gin.Context, build *model.Build, repo *model.Repo, event
},
}
buildCopy := *build
buildCopy.Procs = model.Tree(buildCopy.Procs)
if buildCopy.Procs, err = model.Tree(buildCopy.Procs); err != nil {
return err
}
message.Data, _ = json.Marshal(model.Event{
Type: model.Enqueued,
Repo: *repo,