Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return response with errorsource instead of nil #1069

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
andresmgot marked this conversation as resolved.
Show resolved Hide resolved
return resp, nil
}
if ds, ok := h.(backend.QueryDataHandler); ok {
return ds.QueryData(ctx, req)
Expand Down