Explorar o código

wrap detection methods with a recover function

Mohammed Nafees %!s(int64=4) %!d(string=hai) anos
pai
achega
9789f0f943
Modificáronse 1 ficheiros con 7 adicións e 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 (
 import (
 	"context"
 	"context"
+	"fmt"
 	"net/http"
 	"net/http"
 	"sync"
 	"sync"
 
 
@@ -96,6 +97,12 @@ func (c *GithubGetBuildpackHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
 	wg.Add(len(buildpacks.Runtimes))
 	wg.Add(len(buildpacks.Runtimes))
 	for i := range buildpacks.Runtimes {
 	for i := range buildpacks.Runtimes {
 		go func(idx int) {
 		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(
 			buildpacks.Runtimes[idx].Detect(
 				client, directoryContents, owner, name, request.Dir, repoContentOptions,
 				client, directoryContents, owner, name, request.Dir, repoContentOptions,
 				builderInfoMap[buildpacks.PaketoBuilder], builderInfoMap[buildpacks.HerokuBuilder],
 				builderInfoMap[buildpacks.PaketoBuilder], builderInfoMap[buildpacks.HerokuBuilder],