Pass name to newNotFoundError

This commit is contained in:
Kuba Podgórski 2020-08-27 15:17:07 +02:00
parent c3174efdeb
commit 2ca8ca0605
13 changed files with 79 additions and 80 deletions

40
api.go
View file

@ -217,7 +217,7 @@ func (api *API) Index(ctx context.Context, indexName string) (*Index, error) {
index := api.holder.Index(indexName)
if index == nil {
return nil, newNotFoundError(ErrIndexNotFound)
return nil, newNotFoundError(ErrIndexNotFound, indexName)
}
return index, nil
}
@ -273,7 +273,7 @@ func (api *API) CreateField(ctx context.Context, indexName string, fieldName str
// Find index.
index := api.holder.Index(indexName)
if index == nil {
return nil, newNotFoundError(ErrIndexNotFound)
return nil, newNotFoundError(ErrIndexNotFound, indexName)
}
// Create field.
@ -312,7 +312,7 @@ func (api *API) Field(ctx context.Context, indexName, fieldName string) (*Field,
field := api.holder.Field(indexName, fieldName)
if field == nil {
return nil, newNotFoundError(ErrFieldNotFound)
return nil, newNotFoundError(ErrFieldNotFound, fieldName)
}
return field, nil
}
@ -432,7 +432,7 @@ func (api *API) ImportRoaring(ctx context.Context, indexName, fieldName string,
index, field, err := api.indexField(indexName, fieldName, shard)
if index == nil || field == nil {
return newNotFoundError(ErrFieldNotFound)
return err
}
if err = req.ValidateWithTimestamp(index.CreatedAt(), field.CreatedAt()); err != nil {
@ -501,7 +501,7 @@ func (api *API) DeleteField(ctx context.Context, indexName string, fieldName str
// Find index.
index := api.holder.Index(indexName)
if index == nil {
return newNotFoundError(ErrIndexNotFound)
return newNotFoundError(ErrIndexNotFound, indexName)
}
// Delete field from the index.
@ -532,7 +532,7 @@ func (api *API) DeleteAvailableShard(_ context.Context, indexName, fieldName str
// Find field.
field := api.holder.Field(indexName, fieldName)
if field == nil {
return newNotFoundError(ErrFieldNotFound)
return newNotFoundError(ErrFieldNotFound, fieldName)
}
// Delete shard from the cache.
@ -574,13 +574,13 @@ func (api *API) ExportCSV(ctx context.Context, indexName string, fieldName strin
// Find index.
index := api.holder.Index(indexName)
if index == nil {
return newNotFoundError(ErrIndexNotFound)
return newNotFoundError(ErrIndexNotFound, indexName)
}
// Find field from the index.
field := index.Field(fieldName)
if field == nil {
return newNotFoundError(ErrFieldNotFound)
return newNotFoundError(ErrFieldNotFound, fieldName)
}
// Find the fragment.
@ -739,7 +739,7 @@ func (api *API) TranslateData(ctx context.Context, indexName string, partition i
// Retrieve index from holder.
idx := api.holder.Index(indexName)
if idx == nil {
return nil, ErrIndexNotFound
return nil, newNotFoundError(ErrIndexNotFound, indexName)
}
// Retrieve translatestore from holder.
@ -890,7 +890,7 @@ func (api *API) Views(ctx context.Context, indexName string, fieldName string) (
// Retrieve views.
f := api.holder.Field(indexName, fieldName)
if f == nil {
return nil, ErrFieldNotFound
return nil, newNotFoundError(ErrFieldNotFound, fieldName)
}
// Fetch views.
@ -910,7 +910,7 @@ func (api *API) DeleteView(ctx context.Context, indexName string, fieldName stri
// Retrieve field.
f := api.holder.Field(indexName, fieldName)
if f == nil {
return ErrFieldNotFound
return newNotFoundError(ErrFieldNotFound, fieldName)
}
// Delete the view.
@ -947,7 +947,7 @@ func (api *API) IndexAttrDiff(ctx context.Context, indexName string, blocks []At
// Retrieve index from holder.
index := api.holder.Index(indexName)
if index == nil {
return nil, newNotFoundError(ErrIndexNotFound)
return nil, newNotFoundError(ErrIndexNotFound, indexName)
}
// Retrieve local blocks.
@ -985,7 +985,7 @@ func (api *API) FieldAttrDiff(ctx context.Context, indexName string, fieldName s
// Retrieve index from holder.
f := api.holder.Field(indexName, fieldName)
if f == nil {
return nil, ErrFieldNotFound
return nil, newNotFoundError(ErrFieldNotFound, fieldName)
}
// Retrieve local blocks.
@ -1535,14 +1535,14 @@ func (api *API) indexField(indexName string, fieldName string, shard uint64) (*I
index := api.holder.Index(indexName)
if index == nil {
api.server.logger.Printf("fragment error: index=%s, field=%s, shard=%d, err=%s", indexName, fieldName, shard, ErrIndexNotFound.Error())
return nil, nil, newNotFoundError(ErrIndexNotFound)
return nil, nil, newNotFoundError(ErrIndexNotFound, indexName)
}
// Retrieve field.
field := index.Field(fieldName)
if field == nil {
api.server.logger.Printf("field error: index=%s, field=%s, shard=%d, err=%s", indexName, fieldName, shard, ErrFieldNotFound.Error())
return nil, nil, ErrFieldNotFound
return nil, nil, newNotFoundError(ErrFieldNotFound, fieldName)
}
return index, field, nil
}
@ -1666,7 +1666,7 @@ func (api *API) GetTranslateEntryReader(ctx context.Context, offsets TranslateOf
for indexName, indexMap := range offsets {
index := api.holder.Index(indexName)
if index == nil {
return nil, ErrIndexNotFound
return nil, newNotFoundError(ErrIndexNotFound, indexName)
}
for partitionID, offset := range indexMap.Partitions {
@ -1687,13 +1687,13 @@ func (api *API) GetTranslateEntryReader(ctx context.Context, offsets TranslateOf
for indexName, indexMap := range offsets {
index := api.holder.Index(indexName)
if index == nil {
return nil, ErrIndexNotFound
return nil, newNotFoundError(ErrIndexNotFound, indexName)
}
for fieldName, offset := range indexMap.Fields {
field := index.Field(fieldName)
if field == nil {
return nil, ErrFieldNotFound
return nil, newNotFoundError(ErrFieldNotFound, fieldName)
}
r, err := field.TranslateStore().EntryReader(ctx, uint64(offset))
@ -1732,7 +1732,7 @@ func (api *API) TranslateKeys(ctx context.Context, r io.Reader) (_ []byte, err e
}
} else {
if field := api.holder.Field(req.Index, req.Field); field == nil {
return nil, ErrFieldNotFound
return nil, newNotFoundError(ErrFieldNotFound, req.Field)
} else if fi := field.ForeignIndex(); fi != "" {
ids, err = api.cluster.translateIndexKeys(ctx, fi, req.Keys)
if err != nil {
@ -1768,7 +1768,7 @@ func (api *API) TranslateIDs(ctx context.Context, r io.Reader) (_ []byte, err er
}
} else {
if field := api.holder.Field(req.Index, req.Field); field == nil {
return nil, ErrFieldNotFound
return nil, newNotFoundError(ErrFieldNotFound, req.Field)
} else if fi := field.ForeignIndex(); fi != "" {
keys, err = api.cluster.translateIndexIDs(ctx, fi, req.IDs)
if err != nil {

View file

@ -1586,7 +1586,7 @@ func (c *cluster) followResizeInstruction(instr *ResizeInstruction) error {
// Retrieve field.
f := c.holder.Field(src.Index, src.Field)
if f == nil {
return ErrFieldNotFound
return newNotFoundError(ErrFieldNotFound, src.Field)
}
// Create view.
@ -1638,7 +1638,7 @@ func (c *cluster) followResizeInstruction(instr *ResizeInstruction) error {
idx := c.holder.Index(src.Index)
if idx == nil {
return ErrIndexNotFound
return newNotFoundError(ErrIndexNotFound, src.Index)
}
// Retrieve partition from remote node.
@ -2470,7 +2470,7 @@ func (c *cluster) translateIndexIDSet(ctx context.Context, indexName string, idS
index := c.holder.Index(indexName)
if index == nil {
return nil, ErrIndexNotFound
return nil, newNotFoundError(ErrIndexNotFound, indexName)
}
// Split ids by partition.

View file

@ -142,7 +142,7 @@ func (e *executor) Execute(ctx context.Context, index string, q *pql.Query, shar
idx := e.Holder.Index(index)
if idx == nil {
return resp, ErrIndexNotFound
return resp, newNotFoundError(ErrIndexNotFound, index)
}
needWriteTxn := false
@ -471,7 +471,7 @@ func (e *executor) execute(ctx context.Context, tx Tx, index string, q *pql.Quer
// Round up the number of shards.
idx := e.Holder.Index(index)
if idx == nil {
return nil, ErrIndexNotFound
return nil, newNotFoundError(ErrIndexNotFound, index)
}
shards = idx.AvailableShards().Slice()
if len(shards) == 0 {
@ -745,7 +745,7 @@ func (e *executor) executeCall(ctx context.Context, tx Tx, index string, c *pql.
// Round up the number of shards.
idx := e.Holder.Index(index)
if idx == nil {
return nil, ErrIndexNotFound
return nil, newNotFoundError(ErrIndexNotFound, index)
}
shards = idx.AvailableShards().Slice()
if len(shards) == 0 {
@ -942,13 +942,13 @@ func (e *executor) executeFieldValueCall(ctx context.Context, tx Tx, index strin
// Fetch index.
idx := e.Holder.Index(index)
if idx == nil {
return ValCount{}, ErrIndexNotFound
return ValCount{}, newNotFoundError(ErrIndexNotFound, index)
}
// Fetch field.
field := idx.Field(fieldName)
if field == nil {
return ValCount{}, ErrFieldNotFound
return ValCount{}, newNotFoundError(ErrFieldNotFound, fieldName)
}
var colID uint64
@ -1169,7 +1169,7 @@ func (e *executor) executeSum(ctx context.Context, tx Tx, index string, c *pql.C
if !opt.Remote {
field := e.Holder.Field(index, fieldName)
if field == nil {
return ValCount{}, ErrFieldNotFound
return ValCount{}, newNotFoundError(ErrFieldNotFound, fieldName)
}
if field.Type() == FieldTypeDecimal {
other.DecimalVal = &pql.Decimal{
@ -2114,7 +2114,7 @@ func (e *executor) executeGroupBy(ctx context.Context, tx Tx, index string, c *p
idx := e.Holder.Index(index)
if idx == nil {
return nil, ErrIndexNotFound
return nil, newNotFoundError(ErrIndexNotFound, index)
}
// perform necessary Rows queries (any that have limit or columns args) -
@ -2147,7 +2147,7 @@ func (e *executor) executeGroupBy(ctx context.Context, tx Tx, index string, c *p
}
f := idx.Field(fieldName)
if f == nil {
return nil, ErrFieldNotFound
return nil, newNotFoundError(ErrFieldNotFound, fieldName)
}
switch f.Type() {
case FieldTypeInt:
@ -2654,12 +2654,12 @@ func (e *executor) executeRowsShard(ctx context.Context, tx Tx, index string, fi
// Fetch index.
idx := e.Holder.Index(index)
if idx == nil {
return nil, ErrIndexNotFound
return nil, newNotFoundError(ErrIndexNotFound, index)
}
// Fetch field.
f := e.Holder.Field(index, fieldName)
if f == nil {
return nil, ErrFieldNotFound
return nil, newNotFoundError(ErrFieldNotFound, fieldName)
}
// rowIDs is the result set.
@ -3029,7 +3029,7 @@ func (e *executor) executeExtractShard(ctx context.Context, tx Tx, index string,
// Fetch index.
idx := e.Holder.Index(index)
if idx == nil {
return ExtractedIDMatrix{}, ErrIndexNotFound
return ExtractedIDMatrix{}, newNotFoundError(ErrIndexNotFound, index)
}
// Decompress columns bitmap.
@ -3062,7 +3062,7 @@ func (e *executor) executeExtractShard(ctx context.Context, tx Tx, index string,
// Look up the field.
field := idx.Field(name)
if field == nil {
return ExtractedIDMatrix{}, ErrFieldNotFound
return ExtractedIDMatrix{}, newNotFoundError(ErrFieldNotFound, name)
}
switch field.Type() {
@ -3213,7 +3213,7 @@ func (e *executor) executeRowShard(ctx context.Context, tx Tx, index string, c *
// Fetch index.
idx := e.Holder.Index(index)
if idx == nil {
return nil, ErrIndexNotFound
return nil, newNotFoundError(ErrIndexNotFound, index)
}
// Fetch field name from argument.
@ -3223,7 +3223,7 @@ func (e *executor) executeRowShard(ctx context.Context, tx Tx, index string, c *
}
f := idx.Field(fieldName)
if f == nil {
return nil, ErrFieldNotFound
return nil, newNotFoundError(ErrFieldNotFound, fieldName)
}
// Parse "from" time, if set.
@ -3340,7 +3340,7 @@ func (e *executor) executeRowBSIGroupShard(ctx context.Context, tx Tx, index str
f := e.Holder.Field(index, fieldName)
if f == nil {
return nil, ErrFieldNotFound
return nil, newNotFoundError(ErrFieldNotFound, fieldName)
}
// EQ null _exists - frag.NotNull()
@ -3364,7 +3364,7 @@ func (e *executor) executeRowBSIGroupShard(ctx context.Context, tx Tx, index str
// Make sure the index supports existence tracking.
idx := e.Holder.Index(index)
if idx == nil {
return nil, ErrIndexNotFound
return nil, newNotFoundError(ErrIndexNotFound, index)
} else if idx.existenceField() == nil {
return nil, errors.Errorf("index does not support existence tracking: %s", index)
}
@ -3574,7 +3574,7 @@ func (e *executor) executeNotShard(ctx context.Context, tx Tx, index string, c *
// Make sure the index supports existence tracking.
idx := e.Holder.Index(index)
if idx == nil {
return nil, ErrIndexNotFound
return nil, newNotFoundError(ErrIndexNotFound, index)
} else if idx.existenceField() == nil {
return nil, errors.Errorf("index does not support existence tracking: %s", index)
}
@ -3609,7 +3609,7 @@ func (e *executor) executeAllCallShard(ctx context.Context, tx Tx, index string,
// Make sure the index supports existence tracking.
idx := e.Holder.Index(index)
if idx == nil {
return nil, ErrIndexNotFound
return nil, newNotFoundError(ErrIndexNotFound, index)
} else if idx.existenceField() == nil {
return nil, errors.Errorf("index does not support existence tracking: %s", index)
}
@ -3704,11 +3704,11 @@ func (e *executor) executeClearBit(ctx context.Context, tx Tx, index string, c *
// Retrieve field.
idx := e.Holder.Index(index)
if idx == nil {
return false, ErrIndexNotFound
return false, newNotFoundError(ErrIndexNotFound, index)
}
f := idx.Field(fieldName)
if f == nil {
return false, ErrFieldNotFound
return false, newNotFoundError(ErrFieldNotFound, fieldName)
}
// Int field.
@ -3771,7 +3771,7 @@ func (e *executor) executeClearRow(ctx context.Context, tx Tx, index string, c *
}
field := e.Holder.Field(index, fieldName)
if field == nil {
return false, ErrFieldNotFound
return false, newNotFoundError(ErrFieldNotFound, fieldName)
}
switch field.Type() {
@ -3829,7 +3829,7 @@ func (e *executor) executeClearRowShard(ctx context.Context, tx Tx, index string
field := e.Holder.Field(index, fieldName)
if field == nil {
return false, ErrFieldNotFound
return false, newNotFoundError(ErrFieldNotFound, fieldName)
}
// Remove the row from all views.
@ -3863,7 +3863,7 @@ func (e *executor) executeSetRow(ctx context.Context, tx Tx, indexName string, c
// Find index.
index := e.Holder.Index(indexName)
if index == nil {
return false, newNotFoundError(ErrIndexNotFound)
return false, newNotFoundError(ErrIndexNotFound, indexName)
}
// Create field.
@ -3875,7 +3875,7 @@ func (e *executor) executeSetRow(ctx context.Context, tx Tx, indexName string, c
if err != nil {
// We wrap these because we want to indicate that it wasn't found,
// but also the problem we encountered trying to create it.
return false, newNotFoundError(errors.Wrap(err, "creating field"))
return false, newNotFoundError(errors.Wrap(err, "creating field"), fieldName)
}
}
// Ensure the field type supports Store().
@ -3946,7 +3946,7 @@ func (e *executor) executeSetRowShard(ctx context.Context, tx Tx, index string,
field := e.Holder.Field(index, fieldName)
if field == nil {
return false, ErrFieldNotFound
return false, newNotFoundError(ErrFieldNotFound, fieldName)
}
// Retrieve source row.
@ -4006,11 +4006,11 @@ func (e *executor) executeSet(ctx context.Context, tx Tx, index string, c *pql.C
// Retrieve field.
idx := e.Holder.Index(index)
if idx == nil {
return false, ErrIndexNotFound
return false, newNotFoundError(ErrIndexNotFound, index)
}
f := idx.Field(fieldName)
if f == nil {
return false, ErrFieldNotFound
return false, newNotFoundError(ErrFieldNotFound, fieldName)
}
// Set column on existence field.
@ -4185,7 +4185,7 @@ func (e *executor) executeSetRowAttrs(ctx context.Context, tx Tx, index string,
// Retrieve field.
field := e.Holder.Field(index, fieldName)
if field == nil {
return ErrFieldNotFound
return newNotFoundError(ErrFieldNotFound, fieldName)
}
// Parse labels.
@ -4253,7 +4253,7 @@ func (e *executor) executeBulkSetRowAttrs(ctx context.Context, tx Tx, index stri
// Retrieve field.
f := e.Holder.Field(index, field)
if f == nil {
return nil, ErrFieldNotFound
return nil, newNotFoundError(ErrFieldNotFound, field)
}
rowID, ok, err := c.UintArg("_" + rowLabel)
@ -4291,7 +4291,7 @@ func (e *executor) executeBulkSetRowAttrs(ctx context.Context, tx Tx, index stri
// Retrieve field.
field := e.Holder.Field(index, name)
if field == nil {
return nil, ErrFieldNotFound
return nil, newNotFoundError(ErrFieldNotFound, name)
}
// Set attributes.
@ -4339,7 +4339,7 @@ func (e *executor) executeSetColumnAttrs(ctx context.Context, tx Tx, index strin
// Retrieve index.
idx := e.Holder.Index(index)
if idx == nil {
return ErrIndexNotFound
return newNotFoundError(ErrIndexNotFound, index)
}
col, okCol, errCol := c.UintArg("_" + columnLabel)
@ -4707,7 +4707,7 @@ func (e *executor) collectCallKeySets(ctx context.Context, indexName string, c *
if fieldName != "" {
idx, exists := e.Holder.indexes[indexName]
if !exists {
return errors.Wrapf(ErrIndexNotFound, "%s", indexName)
return newNotFoundError(ErrIndexNotFound, indexName)
}
if field := idx.Field(fieldName); field != nil && field.ForeignIndex() != "" {
foreignIndexName := field.ForeignIndex()
@ -4755,7 +4755,7 @@ func (e *executor) translateCall(ctx context.Context, indexName string, c *pql.C
colKey, rowKey, fieldName := c.TranslateInfo(columnLabel, rowLabel)
idx, exists := e.Holder.indexes[indexName]
if !exists {
return errors.Wrapf(ErrIndexNotFound, "%s", indexName)
return newNotFoundError(ErrIndexNotFound, indexName)
}
if idx.Keys() {
if c.Args[colKey] != nil && !isString(c.Args[colKey]) {
@ -5083,7 +5083,7 @@ func (e *executor) translateResult(ctx context.Context, index string, idx *Index
// TODO: It may be useful to cache this field lookup.
field := idx.Field(g.Field)
if field == nil {
return nil, ErrFieldNotFound
return nil, newNotFoundError(ErrFieldNotFound, g.Field)
}
if field.Keys() {
var key string
@ -5127,7 +5127,7 @@ func (e *executor) translateResult(ctx context.Context, index string, idx *Index
}
if field := idx.Field(fieldName); field == nil {
return nil, ErrFieldNotFound
return nil, newNotFoundError(ErrFieldNotFound, fieldName)
} else if field.Keys() {
other.Keys = make([]string, len(result))
for i, id := range result {
@ -5151,7 +5151,7 @@ func (e *executor) translateResult(ctx context.Context, index string, idx *Index
for i, v := range result.Fields {
field := idx.Field(v)
if field == nil {
return nil, ErrFieldNotFound
return nil, newNotFoundError(ErrFieldNotFound, v)
}
datatype, err := field.Datatype()
@ -5807,7 +5807,7 @@ func newGroupByIterator(executor *executor, tx Tx, rowIDs []RowIDs, children []*
}
field := holder.Field(index, fieldName)
if field == nil {
return nil, ErrFieldNotFound
return nil, newNotFoundError(ErrFieldNotFound, fieldName)
}
gbi.fields[i].Field = fieldName

View file

@ -961,7 +961,7 @@ func (h *Holder) DeleteIndex(name string) error {
// Confirm index exists.
index := h.index(name)
if index == nil {
return newNotFoundError(ErrIndexNotFound)
return newNotFoundError(ErrIndexNotFound, name)
}
// Close index.
@ -1329,7 +1329,7 @@ func (s *holderSyncer) syncField(index, name string) error {
// Retrieve attributes from differing blocks.
// Skip update and recomputation if no attributes have changed.
m, err := s.Cluster.InternalClient.RowAttrDiff(ctx, &node.URI, index, name, blks)
if err == ErrFieldNotFound {
if errors.Cause(err) == ErrFieldNotFound {
continue // field not created remotely yet, skip
} else if err != nil {
return errors.Wrap(err, "getting differing blocks")
@ -1358,7 +1358,7 @@ func (s *holderSyncer) syncFragment(index, field, view string, shard uint64) err
// Retrieve local field.
f := s.Holder.Field(index, field)
if f == nil {
return ErrFieldNotFound
return newNotFoundError(ErrFieldNotFound, field)
}
// Ensure view exists locally.

View file

@ -1101,7 +1101,7 @@ func (c *InternalClient) RowAttrDiff(ctx context.Context, uri *pilosa.URI, index
resp, err := c.executeRequest(req.WithContext(ctx))
if err != nil {
if resp != nil && resp.StatusCode == http.StatusNotFound {
return nil, pilosa.ErrFieldNotFound
return nil, errors.Wrap(pilosa.ErrFieldNotFound, field)
}
return nil, err
}

View file

@ -636,7 +636,7 @@ func (i *Index) DeleteField(name string) error {
// Confirm field exists.
f := i.field(name)
if f == nil {
return newNotFoundError(ErrFieldNotFound)
return newNotFoundError(ErrFieldNotFound, name)
}
// Close field.

2
mtx.go
View file

@ -280,7 +280,7 @@ func (mtx *MultiTx) tx(index string, shard uint64) (_ Tx, err error) {
idx := mtx.index
if mtx.holder != nil {
if idx = mtx.holder.Index(index); idx == nil {
return nil, ErrIndexNotFound
return nil, newNotFoundError(ErrIndexNotFound, index)
}
}

View file

@ -119,13 +119,11 @@ func newConflictError(err error) ConflictError {
// NotFoundError wraps an error value to signify that a resource was not found
// such that in an HTTP scenario, http.StatusNotFound would be returned.
type NotFoundError struct {
error
}
type NotFoundError error
// newNotFoundError returns err wrapped in a NotFoundError.
func newNotFoundError(err error) NotFoundError {
return NotFoundError{err}
func newNotFoundError(err error, name string) NotFoundError {
return NotFoundError(errors.WithMessage(err, name))
}
type PreconditionFailedError struct {

View file

@ -310,11 +310,11 @@ func (tx *RoaringTx) getFragment(index, field, view string, shard uint64) (*frag
// only thing we can try is the cached index, and hope we aren't being asked for a foreign index.
f = tx.Index.Field(field)
if f == nil {
return nil, ErrFieldNotFound
return nil, newNotFoundError(ErrFieldNotFound, field)
}
} else {
if f = idx.Field(field); f == nil {
return nil, ErrFieldNotFound
return nil, newNotFoundError(ErrFieldNotFound, field)
}
}
}

View file

@ -621,7 +621,7 @@ func TestHandler_Endpoints(t *testing.T) {
h.ServeHTTP(w, test.MustNewHTTPRequest("POST", "/index/i0/query", strings.NewReader(`Row(row=30)`)))
if w.Code != gohttp.StatusBadRequest {
t.Fatalf("unexpected status code: %d", w.Code)
} else if body := w.Body.String(); body != `{"error":"executing: map reduce: field not found"}`+"\n" {
} else if body := w.Body.String(); body != `{"error":"executing: map reduce: row: field not found"}`+"\n" {
t.Fatalf("unexpected body: %q", body)
}
})
@ -638,7 +638,7 @@ func TestHandler_Endpoints(t *testing.T) {
var resp pilosa.QueryResponse
if err := cmd.API.Serializer.Unmarshal(w.Body.Bytes(), &resp); err != nil {
t.Fatal(err)
} else if s := resp.Err.Error(); s != `executing: map reduce: field not found` {
} else if s := resp.Err.Error(); s != `executing: map reduce: row: field not found` {
t.Fatalf("unexpected error: %s", s)
}
})
@ -1156,7 +1156,7 @@ func TestHandler_Endpoints(t *testing.T) {
h.ServeHTTP(w, r)
if w.Code != gohttp.StatusNotFound {
t.Errorf("unexpected status code: %d", w.Code)
} else if w.Body.String() != `{"success":false,"error":{"message":"deleting field: field not found"}}`+"\n" {
} else if w.Body.String() != `{"success":false,"error":{"message":"deleting field: fld1: field not found"}}`+"\n" {
t.Errorf("unexpected body: %q", w.Body.String())
}

View file

@ -247,7 +247,7 @@ func extractWhere(index *pilosa.Index, expr sqlparser.Expr) (string, error) {
field := index.Field(parseCol.name)
if field == nil {
return "", pilosa.ErrFieldNotFound
return "", errors.Wrap(pilosa.ErrFieldNotFound, parseCol.name)
}
switch field.Type() {

View file

@ -98,7 +98,7 @@ func (s *ShowHandler) execShowFields(ctx context.Context, showStmt *sqlparser.Sh
return nil, errors.Wrap(err, "getting schema")
}
if index == nil {
return nil, pilosa.ErrIndexNotFound
return nil, errors.WithMessage(pilosa.ErrIndexNotFound, indexName)
}
fields := index.Fields()
sz := len(fields)

View file

@ -23,6 +23,7 @@ import (
"github.com/pilosa/pilosa/v2/boltdb"
"github.com/pilosa/pilosa/v2/pql"
"github.com/pilosa/pilosa/v2/testhook"
"github.com/pkg/errors"
)
var panicOn = pilosa.PanicOn
@ -104,11 +105,11 @@ func (h *Holder) Row(index, field string, rowID uint64) *pilosa.Row {
func (h *Holder) ReadRow(index, field string, rowID uint64) *pilosa.Row {
idx := h.Holder.Index(index)
if idx == nil {
panic(pilosa.ErrIndexNotFound)
panic(errors.Wrap(pilosa.ErrIndexNotFound, index))
}
f := idx.Field(field)
if f == nil {
panic(pilosa.ErrFieldNotFound)
panic(errors.Wrap(pilosa.ErrFieldNotFound, field))
}
tx := idx.Txf.NewTx(pilosa.Txo{Write: false, Field: f})
defer tx.Rollback()