Selaa lähdekoodia

enhance error message if phantomjs executable is not found

if arm build, explain that phantomjs is not included by default in arm
builds. If not explain that phantom js isn't installed correctly
Marcus Efraimsson 7 vuotta sitten
vanhempi
commit
f106de0efd
3 muutettua tiedostoa jossa 17 lisäystä ja 0 poistoa
  1. 11 0
      pkg/api/render.go
  2. 1 0
      pkg/services/rendering/interface.go
  3. 5 0
      pkg/services/rendering/phantomjs.go

+ 11 - 0
pkg/api/render.go

@@ -3,7 +3,9 @@ package api
 import (
 	"fmt"
 	"net/http"
+	"runtime"
 	"strconv"
+	"strings"
 	"time"
 
 	m "github.com/grafana/grafana/pkg/models"
@@ -55,6 +57,15 @@ func (hs *HTTPServer) RenderToPng(c *m.ReqContext) {
 		return
 	}
 
+	if err != nil && err == rendering.ErrPhantomJSNotInstalled {
+		if strings.HasPrefix(runtime.GOARCH, "arm") {
+			c.Handle(500, "Rendering failed - PhantomJS isn't included in arm build per default", err)
+		} else {
+			c.Handle(500, "Rendering failed - PhantomJS isn't installed correctly", err)
+		}
+		return
+	}
+
 	if err != nil {
 		c.Handle(500, "Rendering failed.", err)
 		return

+ 1 - 0
pkg/services/rendering/interface.go

@@ -10,6 +10,7 @@ import (
 
 var ErrTimeout = errors.New("Timeout error. You can set timeout in seconds with &timeout url parameter")
 var ErrNoRenderer = errors.New("No renderer plugin found nor is an external render server configured")
+var ErrPhantomJSNotInstalled = errors.New("PhantomJS executable not found")
 
 type Opts struct {
 	Width    int

+ 5 - 0
pkg/services/rendering/phantomjs.go

@@ -24,6 +24,11 @@ func (rs *RenderingService) renderViaPhantomJS(ctx context.Context, opts Opts) (
 
 	url := rs.getURL(opts.Path)
 	binPath, _ := filepath.Abs(filepath.Join(rs.Cfg.PhantomDir, executable))
+	if _, err := os.Stat(binPath); os.IsNotExist(err) {
+		rs.log.Error("executable not found", "executable", binPath)
+		return nil, ErrPhantomJSNotInstalled
+	}
+
 	scriptPath, _ := filepath.Abs(filepath.Join(rs.Cfg.PhantomDir, "render.js"))
 	pngPath := rs.getFilePathForNewImage()