Skip to content

Commit 91f532d

Browse files
committed
fix: Remove various panic's
1 parent 336f728 commit 91f532d

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

storage/reads/array_cursor.gen.go.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func newLimitArrayCursor(cur cursors.Cursor) (cursors.Cursor, error) {
2727
default:
2828
return nil, &errors2.Error{
2929
Code: errors2.EInvalid,
30-
Msg: fmt.Sprintf("unreachable: %s", arrayCursorType(cur)),
30+
Msg: fmt.Sprintf("unsupported limit array cursor type: %s", arrayCursorType(cur)),
3131
}
3232
}
3333
}
@@ -44,7 +44,7 @@ func newWindowFirstArrayCursor(cur cursors.Cursor, window interval.Window) (curs
4444
default:
4545
return nil, &errors2.Error{
4646
Code: errors2.EInvalid,
47-
Msg: fmt.Sprintf("unreachable: %s", arrayCursorType(cur)),
47+
Msg: fmt.Sprintf("unsupported window first cursor type: %s", arrayCursorType(cur)),
4848
}
4949
}
5050
}
@@ -61,7 +61,7 @@ func newWindowLastArrayCursor(cur cursors.Cursor, window interval.Window) (curso
6161
default:
6262
return nil, &errors2.Error{
6363
Code: errors2.EInvalid,
64-
Msg: fmt.Sprintf("unreachable: %s", arrayCursorType(cur)),
64+
Msg: fmt.Sprintf("unsupported window last cursor type: %s", arrayCursorType(cur)),
6565
}
6666
}
6767
}
@@ -75,7 +75,7 @@ func newWindowCountArrayCursor(cur cursors.Cursor, window interval.Window) (curs
7575
default:
7676
return nil, &errors2.Error{
7777
Code: errors2.EInvalid,
78-
Msg: fmt.Sprintf("unreachable: %s", arrayCursorType(cur)),
78+
Msg: fmt.Sprintf("unsupported window count cursor type: %s", arrayCursorType(cur)),
7979
}
8080
}
8181
}

storage/reads/array_cursor.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package reads
33
import (
44
"context"
55
"fmt"
6+
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
67

78
"github.com/influxdata/flux/interval"
89
"github.com/influxdata/influxdb/v2/storage/reads/datatypes"
@@ -46,8 +47,10 @@ func newWindowAggregateArrayCursor(ctx context.Context, agg *datatypes.Aggregate
4647
case datatypes.Aggregate_AggregateTypeMean:
4748
return newWindowMeanArrayCursor(cursor, window)
4849
default:
49-
// TODO(sgc): should be validated higher up
50-
panic("invalid aggregate")
50+
return nil, &errors2.Error{
51+
Code: errors2.EInvalid,
52+
Msg: fmt.Sprintf("unsupported window aggregate cursor: %s", agg.Type),
53+
}
5154
}
5255
}
5356

@@ -101,7 +104,7 @@ func newMultiShardArrayCursors(ctx context.Context, start, end int64, asc bool)
101104
return m
102105
}
103106

104-
func (m *multiShardArrayCursors) createCursor(row SeriesRow) cursors.Cursor {
107+
func (m *multiShardArrayCursors) createCursor(row SeriesRow) (cursors.Cursor, error) {
105108
m.req.Name = row.Name
106109
m.req.Tags = row.SeriesTags
107110
m.req.Field = row.Field
@@ -120,26 +123,29 @@ func (m *multiShardArrayCursors) createCursor(row SeriesRow) cursors.Cursor {
120123
}
121124

122125
if cur == nil || err != nil {
123-
return nil
126+
return nil, nil
124127
}
125128

126129
switch c := cur.(type) {
127130
case cursors.IntegerArrayCursor:
128131
m.cursors.i.reset(c, row.Query, cond)
129-
return &m.cursors.i
132+
return &m.cursors.i, nil
130133
case cursors.FloatArrayCursor:
131134
m.cursors.f.reset(c, row.Query, cond)
132-
return &m.cursors.f
135+
return &m.cursors.f, nil
133136
case cursors.UnsignedArrayCursor:
134137
m.cursors.u.reset(c, row.Query, cond)
135-
return &m.cursors.u
138+
return &m.cursors.u, nil
136139
case cursors.StringArrayCursor:
137140
m.cursors.s.reset(c, row.Query, cond)
138-
return &m.cursors.s
141+
return &m.cursors.s, nil
139142
case cursors.BooleanArrayCursor:
140143
m.cursors.b.reset(c, row.Query, cond)
141-
return &m.cursors.b
144+
return &m.cursors.b, nil
142145
default:
143-
panic(fmt.Sprintf("unreachable: %T", cur))
146+
return nil, &errors2.Error{
147+
Code: errors2.EInvalid,
148+
Msg: fmt.Sprintf("unsupported cursor type while creating cursor: %s", arrayCursorType(cur)),
149+
}
144150
}
145151
}

0 commit comments

Comments
 (0)