From c9ec2dd07faa30a02a69c0459c918645732149f4 Mon Sep 17 00:00:00 2001 From: "Christopher M. Wolff" Date: Tue, 11 Dec 2018 07:57:32 -0800 Subject: [PATCH] fix(query): set error code "invalid" when controller reports error (#1812) Fixes flux#268 --- query/control/controller.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/query/control/controller.go b/query/control/controller.go index 7c52e9417b..16bd8e9165 100644 --- a/query/control/controller.go +++ b/query/control/controller.go @@ -6,6 +6,7 @@ import ( "github.com/influxdata/flux" "github.com/influxdata/flux/control" + "github.com/influxdata/platform" "github.com/influxdata/platform/query" "github.com/prometheus/client_golang/prometheus" ) @@ -25,13 +26,23 @@ func New(config control.Config) *Controller { return &Controller{c: c} } -// Query satisifies the AsyncQueryService while ensuring the request is propogated on the context. +// Query satisfies the AsyncQueryService while ensuring the request is propagated on the context. func (c *Controller) Query(ctx context.Context, req *query.Request) (flux.Query, error) { // Set the request on the context so platform specific Flux operations can retrieve it later. ctx = query.ContextWithRequest(ctx, req) // Set the org label value for controller metrics ctx = context.WithValue(ctx, orgLabel, req.OrganizationID.String()) - return c.c.Query(ctx, req.Compiler) + q, err := c.c.Query(ctx, req.Compiler) + if err != nil { + // If the controller reports an error, it's usually because of a syntax error + // or other problem that the client must fix. + return q, &platform.Error{ + Code: platform.EInvalid, + Err: err, + } + } + + return q, nil } // PrometheusCollectors satisifies the prom.PrometheusCollector interface.