2023-07-21 05:38:29 -05:00
|
|
|
package expr
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2023-09-13 12:58:16 -05:00
|
|
|
"fmt"
|
2023-07-21 05:38:29 -05:00
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/util/errutil"
|
|
|
|
)
|
|
|
|
|
2023-08-22 05:52:24 -05:00
|
|
|
var ConversionError = errutil.BadRequest("sse.readDataError").MustTemplate(
|
2023-07-21 05:38:29 -05:00
|
|
|
"[{{ .Public.refId }}] got error: {{ .Error }}",
|
|
|
|
errutil.WithPublic(
|
|
|
|
"failed to read data from from query {{ .Public.refId }}: {{ .Public.error }}",
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2023-09-13 12:58:16 -05:00
|
|
|
func makeConversionError(refID string, err error) error {
|
2023-07-21 05:38:29 -05:00
|
|
|
data := errutil.TemplateData{
|
|
|
|
// Conversion errors should only have meta information in errors
|
2023-08-30 10:46:47 -05:00
|
|
|
Public: map[string]any{
|
2023-07-21 05:38:29 -05:00
|
|
|
"refId": refID,
|
|
|
|
"error": err.Error(),
|
|
|
|
},
|
|
|
|
Error: err,
|
|
|
|
}
|
|
|
|
return ConversionError.Build(data)
|
|
|
|
}
|
|
|
|
|
2023-08-22 05:52:24 -05:00
|
|
|
var QueryError = errutil.BadRequest("sse.dataQueryError").MustTemplate(
|
2023-07-21 05:38:29 -05:00
|
|
|
"failed to execute query [{{ .Public.refId }}]: {{ .Error }}",
|
|
|
|
errutil.WithPublic(
|
|
|
|
"failed to execute query [{{ .Public.refId }}]: {{ .Public.error }}",
|
|
|
|
))
|
|
|
|
|
|
|
|
func MakeQueryError(refID, datasourceUID string, err error) error {
|
|
|
|
var pErr error
|
|
|
|
var utilErr errutil.Error
|
|
|
|
// See if this is grafana error, if so, grab public message
|
|
|
|
if errors.As(err, &utilErr) {
|
|
|
|
pErr = utilErr.Public()
|
|
|
|
} else {
|
|
|
|
pErr = err
|
|
|
|
}
|
|
|
|
|
|
|
|
data := errutil.TemplateData{
|
2023-08-30 10:46:47 -05:00
|
|
|
Public: map[string]any{
|
2023-07-21 05:38:29 -05:00
|
|
|
"refId": refID,
|
|
|
|
"datasourceUID": datasourceUID,
|
|
|
|
"error": pErr.Error(),
|
|
|
|
},
|
|
|
|
Error: err,
|
|
|
|
}
|
|
|
|
|
|
|
|
return QueryError.Build(data)
|
|
|
|
}
|
2023-09-13 12:58:16 -05:00
|
|
|
|
|
|
|
var depErrStr = "did not execute expression [{{ .Public.refId }}] due to a failure to of the dependent expression or query [{{.Public.depRefId}}]"
|
|
|
|
|
|
|
|
var DependencyError = errutil.NewBase(
|
|
|
|
errutil.StatusBadRequest, "sse.dependencyError").MustTemplate(
|
|
|
|
depErrStr,
|
|
|
|
errutil.WithPublic(depErrStr))
|
|
|
|
|
|
|
|
func makeDependencyError(refID, depRefID string) error {
|
|
|
|
data := errutil.TemplateData{
|
|
|
|
Public: map[string]interface{}{
|
|
|
|
"refId": refID,
|
|
|
|
"depRefId": depRefID,
|
|
|
|
},
|
|
|
|
Error: fmt.Errorf("did not execute expression %v due to a failure to of the dependent expression or query %v", refID, depRefID),
|
|
|
|
}
|
|
|
|
|
|
|
|
return DependencyError.Build(data)
|
|
|
|
}
|
|
|
|
|
|
|
|
var unexpectedNodeTypeErrString = "expected executable node type but got node type [{{ .Public.nodeType }} for refid [{{ .Public.refId}}]"
|
|
|
|
|
|
|
|
var UnexpectedNodeTypeError = errutil.NewBase(
|
|
|
|
errutil.StatusBadRequest, "sse.unexpectedNodeType").MustTemplate(
|
|
|
|
unexpectedNodeTypeErrString,
|
|
|
|
errutil.WithPublic(unexpectedNodeTypeErrString))
|
|
|
|
|
|
|
|
func makeUnexpectedNodeTypeError(refID, nodeType string) error {
|
|
|
|
data := errutil.TemplateData{
|
|
|
|
Public: map[string]interface{}{
|
|
|
|
"refId": refID,
|
|
|
|
"nodeType": nodeType,
|
|
|
|
},
|
|
|
|
Error: fmt.Errorf("expected executable node type but got node type %v for refId %v", nodeType, refID),
|
|
|
|
}
|
|
|
|
|
|
|
|
return UnexpectedNodeTypeError.Build(data)
|
|
|
|
}
|