Skip to content

Commit 0e93062

Browse files
authored
Rename QueryContext.RawQuals UnsafeQuals. Remove panic after context cancellation - leave it to the plugin to handle context cancellation. #17 (#126)
1 parent 22c7018 commit 0e93062

File tree

5 files changed

+10
-24
lines changed

5 files changed

+10
-24
lines changed

plugin/errors.go

-3
This file was deleted.

plugin/hydrate.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,8 @@ func WrapHydrate(hydrateFunc HydrateFunc, shouldIgnoreError ErrorPredicate) Hydr
3636
return func(ctx context.Context, d *QueryData, h *HydrateData) (item interface{}, err error) {
3737
defer func() {
3838
if r := recover(); r != nil {
39-
if helpers.ToError(r).Error() == contextCancelledError {
40-
// if the error was a context cancellation, just trace it - this is not an error
41-
log.Printf("[TRACE] hydrate function %s terminated with a context cancellation", helpers.GetFunctionName(hydrateFunc))
42-
} else {
43-
log.Printf("[WARN] recovered a panic from a wrapped hydrate function: %v\n", r)
44-
err = status.Error(codes.Internal, fmt.Sprintf("hydrate function %s failed with panic %v", helpers.GetFunctionName(hydrateFunc), r))
45-
}
39+
log.Printf("[WARN] recovered a panic from a wrapped hydrate function: %v\n", r)
40+
err = status.Error(codes.Internal, fmt.Sprintf("hydrate function %s failed with panic %v", helpers.GetFunctionName(hydrateFunc), r))
4641
}
4742
}()
4843
// call the underlying get function

plugin/query_context.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import (
55
)
66

77
type QueryContext struct {
8-
Columns []string
9-
RawQuals map[string]*proto.Quals
10-
Limit *int64
8+
Columns []string
9+
UnsafeQuals map[string]*proto.Quals
10+
Limit *int64
1111
}
1212

1313
// NewQueryContext maps from a proto.QueryContext to a plugin.QueryContext.
1414
// the only difference is the representation of the limit (as protobuf does not support pointers)
1515
func NewQueryContext(p *proto.QueryContext) *QueryContext {
1616
q := &QueryContext{
17-
Columns: p.Columns,
18-
RawQuals: p.Quals,
17+
Columns: p.Columns,
18+
UnsafeQuals: p.Quals,
1919
}
2020
if p.Limit != nil {
2121
q.Limit = &p.Limit.Value

plugin/query_data.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func (d *QueryData) SetFetchType(table *Table) {
131131
d.FetchType = fetchTypeGet
132132

133133
// build a qual map from Get key columns
134-
qualMap := NewKeyColumnQualValueMap(d.QueryContext.RawQuals, table.Get.KeyColumns)
134+
qualMap := NewKeyColumnQualValueMap(d.QueryContext.UnsafeQuals, table.Get.KeyColumns)
135135
// now see whether the qual map has everything required for the get call
136136
if satisfied, _ := qualMap.SatisfiesKeyColumns(table.Get.KeyColumns); satisfied {
137137
d.KeyColumnQuals = qualMap.ToEqualsQualValueMap()
@@ -144,7 +144,7 @@ func (d *QueryData) SetFetchType(table *Table) {
144144
// if there is a list config default to list, even is we are missing required quals
145145
d.FetchType = fetchTypeList
146146
if len(table.List.KeyColumns) > 0 {
147-
d.Quals = NewKeyColumnQualValueMap(d.QueryContext.RawQuals, table.List.KeyColumns)
147+
d.Quals = NewKeyColumnQualValueMap(d.QueryContext.UnsafeQuals, table.List.KeyColumns)
148148
}
149149
}
150150
}
@@ -228,12 +228,6 @@ func (d *QueryData) verifyCallerIsListCall(callingFunction string) bool {
228228
}
229229

230230
func (d *QueryData) streamLeafListItem(ctx context.Context, item interface{}) {
231-
// if the context is cancelled, panic to break out
232-
select {
233-
case <-d.stream.Context().Done():
234-
panic(contextCancelledError)
235-
default:
236-
}
237231

238232
// create rowData, passing matrixItem from context
239233
rd := newRowData(d, item)

plugin/table_fetch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (t *Table) fetchItems(ctx context.Context, queryData *QueryData) error {
5555
return t.executeGetCall(ctx, queryData)
5656
}
5757
if t.List == nil {
58-
log.Printf("[WARN] query is not a get call, but no list call is defined, quals: %v", grpc.QualMapToString(queryData.QueryContext.RawQuals))
58+
log.Printf("[WARN] query is not a get call, but no list call is defined, quals: %v", grpc.QualMapToString(queryData.QueryContext.UnsafeQuals))
5959
panic("query is not a get call, but no list call is defined")
6060
}
6161

0 commit comments

Comments
 (0)