Skip to content

Commit

Permalink
fix: return response with errorsource instead of nil (#1069)
Browse files Browse the repository at this point in the history
  • Loading branch information
njvrzm authored Sep 6, 2024
1 parent b6bc9e2 commit be0c152
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion internal/automanagement/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package automanagement

import (
"context"
"errors"

"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt"
"github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand All @@ -27,7 +29,18 @@ func NewManager(instanceManager instancemgmt.InstanceManager) *Manager {
func (m *Manager) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
h, err := m.Get(ctx, req.PluginContext)
if err != nil {
return nil, err
if len(req.Queries) == 0 {
// shouldn't be possible, but just in case
return nil, err
}
var esErr errorsource.Error
ok := errors.As(err, &esErr)
if !ok { // not an errorsource error, return opaquely
return nil, err
}
resp := backend.NewQueryDataResponse()
errorsource.AddErrorToResponse(req.Queries[0].RefID, resp, err)
return resp, nil
}
if ds, ok := h.(backend.QueryDataHandler); ok {
return ds.QueryData(ctx, req)
Expand Down

0 comments on commit be0c152

Please sign in to comment.