Skip to content

Commit b2a1024

Browse files
authoredFeb 24, 2025
AWSDS: Add QueryExecutionError type, prepare 0.32.0 (#205)
1 parent 7d9319d commit b2a1024

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed
 

‎CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## 0.32.0
6+
7+
- AWSDS: Add QueryExecutionError type
8+
59
## 0.31.8
610

711
- Bump github.com/grafana/grafana-plugin-sdk-go from 0.265.0 to 0.266.0 in the all-go-dependencies group by @dependabot in https://github.com/grafana/grafana-aws-sdk/pull/204

‎pkg/awsds/asyncDatasource.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,20 @@ func (ds *AsyncAWSDatasource) QueryData(ctx context.Context, req *backend.QueryD
119119
var err error
120120
frames, err = ds.handleAsyncQuery(ctx, query, req.PluginContext.DataSourceInstanceSettings.UID)
121121
if err != nil {
122-
response.Set(query.RefID, errorsource.Response(err))
122+
errorResponse := errorsource.Response(err)
123+
var qeError *QueryExecutionError
124+
// checking if we know the cause of downstream error
125+
if errors.As(err, &qeError) {
126+
errorResponse.Status = backend.StatusInternal
127+
switch qeError.Cause {
128+
// make sure error.status matches the downstream cause, if provided
129+
case QueryFailedInternal:
130+
errorResponse.Status = backend.StatusInternal
131+
case QueryFailedUser:
132+
errorResponse.Status = backend.StatusBadRequest
133+
}
134+
}
135+
response.Set(query.RefID, errorResponse)
123136
} else {
124137
response.Set(query.RefID, backend.DataResponse{Frames: frames})
125138
}

‎pkg/awsds/types.go

+25
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,31 @@ const (
4747
QueryFailed
4848
)
4949

50+
type DownstreamErrorCause uint32
51+
52+
const (
53+
QueryFailedInternal DownstreamErrorCause = iota
54+
QueryFailedUser
55+
)
56+
57+
// QueryExecutionError error type can be returned from datasource's Execute or QueryStatus methods
58+
// this will mark the downstream cause in errorResponse.Status
59+
type QueryExecutionError struct {
60+
Err error
61+
Cause DownstreamErrorCause
62+
}
63+
64+
func (e *QueryExecutionError) Error() string {
65+
if e.Err != nil {
66+
return e.Err.Error()
67+
}
68+
return ""
69+
}
70+
71+
func (e *QueryExecutionError) Unwrap() error {
72+
return e.Err
73+
}
74+
5075
func (qs QueryStatus) Finished() bool {
5176
return qs == QueryCanceled || qs == QueryFailed || qs == QueryFinished
5277
}

0 commit comments

Comments
 (0)