Просмотр исходного кода

wrap detection methods with a recover function

Mohammed Nafees 4 лет назад
Родитель
Сommit
9789f0f943
1 измененных файлов с 7 добавлено и 0 удалено
  1. 7 0
      api/server/handlers/gitinstallation/get_buildpack.go

+ 7 - 0
api/server/handlers/gitinstallation/get_buildpack.go

@@ -2,6 +2,7 @@ package gitinstallation
 
 import (
 	"context"
+	"fmt"
 	"net/http"
 	"sync"
 
@@ -96,6 +97,12 @@ func (c *GithubGetBuildpackHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
 	wg.Add(len(buildpacks.Runtimes))
 	for i := range buildpacks.Runtimes {
 		go func(idx int) {
+			defer func() {
+				if rec := recover(); rec != nil {
+					c.HandleAPIError(w, r, apierrors.NewErrInternal(fmt.Errorf("panic detected in runtime detection")))
+					return
+				}
+			}()
 			buildpacks.Runtimes[idx].Detect(
 				client, directoryContents, owner, name, request.Dir, repoContentOptions,
 				builderInfoMap[buildpacks.PaketoBuilder], builderInfoMap[buildpacks.HerokuBuilder],