Explorar el Código

wrap detection methods with a recover function

Mohammed Nafees hace 4 años
padre
commit
9789f0f943
Se han modificado 1 ficheros con 7 adiciones y 0 borrados
  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],