From dc6c92771b133478272e63e5049375bff0f85cbf Mon Sep 17 00:00:00 2001 From: Alan Bernstein Date: Mon, 8 Feb 2021 17:25:38 -0600 Subject: [PATCH] Fail entire /schema/details request if one field query fails --- api.go | 7 +++---- http/handler.go | 6 +++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/api.go b/api.go index ff5b7c6b4..55ea78af4 100644 --- a/api.go +++ b/api.go @@ -997,7 +997,7 @@ func (api *API) Schema(ctx context.Context) []*IndexInfo { // SchemaDetails returns information about each index in Pilosa including which // fields they contain, and additional field information such as cardinality -func (api *API) SchemaDetails(ctx context.Context) []*IndexInfo { +func (api *API) SchemaDetails(ctx context.Context) ([]*IndexInfo, error) { span, _ := tracing.StartSpanFromContext(ctx, "API.Schema") defer span.Finish() schema := api.holder.Schema(false) @@ -1007,8 +1007,7 @@ func (api *API) SchemaDetails(ctx context.Context) []*IndexInfo { req := QueryRequest{Index: index.Name, Query: q} resp, err := api.query(ctx, &req) if err != nil { - // TODO ? - continue + return schema, errors.Wrapf(err, "querying cardinality (%s/%s)", index.Name, field.Name) } if len(resp.Results) == 0 { continue @@ -1018,7 +1017,7 @@ func (api *API) SchemaDetails(ctx context.Context) []*IndexInfo { } } } - return schema + return schema, nil } // ApplySchema takes the given schema and applies it across the diff --git a/http/handler.go b/http/handler.go index 14ef35fe1..5e8aad1ef 100644 --- a/http/handler.go +++ b/http/handler.go @@ -681,7 +681,11 @@ func (h *Handler) handleGetSchemaDetails(w http.ResponseWriter, r *http.Request) } w.Header().Set("Content-Type", "application/json") - schema := h.api.SchemaDetails(r.Context()) + schema, err := h.api.SchemaDetails(r.Context()) + if err != nil { + h.logger.Printf("error getting detailed schema: %s", err) + return + } if err := json.NewEncoder(w).Encode(pilosa.Schema{Indexes: schema}); err != nil { h.logger.Printf("write schema response error: %s", err) }