mirror of
https://github.com/grafana/grafana.git
synced 2026-07-30 00:08:10 -05:00
Chore: Add errutils helpers (#73577)
Add helpers for the errutil package in favor of errutil.NewBase.
This commit is contained in:
@@ -19,8 +19,20 @@ code, and so forth are carried by the error.
|
|||||||
For a service, declare the different categories of errors that may occur
|
For a service, declare the different categories of errors that may occur
|
||||||
from your service (this corresponds to what you might want to have
|
from your service (this corresponds to what you might want to have
|
||||||
specific public error messages or their templates for) by globally
|
specific public error messages or their templates for) by globally
|
||||||
constructing variables using the `errutil.NewBase(status, messageID, opts...)`
|
constructing variables using the `errutil.<status>(status, messageID, opts...)`
|
||||||
function.
|
functions, e.g.
|
||||||
|
|
||||||
|
- `errutil.NotFound(messageID, opts...)`
|
||||||
|
- `errutil.BadRequest(messageID, opts...)`
|
||||||
|
- `errutil.ValidationFailed(messageID, opts...)`
|
||||||
|
- `errutil.Internal(messageID, opts...)`
|
||||||
|
- `errutil.Timeout(messageID, opts...)`
|
||||||
|
- `errutil.Unauthorized(messageID, opts...)`
|
||||||
|
- `errutil.Forbidden(messageID, opts...)`
|
||||||
|
- `errutil.TooManyRequests(messageID, opts...)`
|
||||||
|
- `errutil.NotImplemented(messageID, opts...)`
|
||||||
|
|
||||||
|
Above functions uses `errutil.NewBase(status, messageID, opts...)` under the covers, and that function should in general only be used outside the `errutil` package for `errutil.StatusUnknown`, e.g. when there are no accurate status code available/provided.
|
||||||
|
|
||||||
The status code loosely corresponds to HTTP status codes and provides a
|
The status code loosely corresponds to HTTP status codes and provides a
|
||||||
default log level for errors to ensure that the request logging is
|
default log level for errors to ensure that the request logging is
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ func TestErrors(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "grafana error with fallback to other error",
|
name: "grafana error with fallback to other error",
|
||||||
|
|
||||||
err: errutil.NewBase(errutil.StatusTimeout, "thing.timeout").Errorf("whoops"),
|
err: errutil.Timeout("thing.timeout").Errorf("whoops"),
|
||||||
statusCode: http.StatusBadRequest,
|
statusCode: http.StatusBadRequest,
|
||||||
message: genericErrorMessage,
|
message: genericErrorMessage,
|
||||||
|
|
||||||
|
|||||||
+2
-6
@@ -6,10 +6,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/util/errutil"
|
"github.com/grafana/grafana/pkg/util/errutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ConversionError = errutil.NewBase(
|
var ConversionError = errutil.BadRequest("sse.readDataError").MustTemplate(
|
||||||
errutil.StatusBadRequest,
|
|
||||||
"sse.readDataError",
|
|
||||||
).MustTemplate(
|
|
||||||
"[{{ .Public.refId }}] got error: {{ .Error }}",
|
"[{{ .Public.refId }}] got error: {{ .Error }}",
|
||||||
errutil.WithPublic(
|
errutil.WithPublic(
|
||||||
"failed to read data from from query {{ .Public.refId }}: {{ .Public.error }}",
|
"failed to read data from from query {{ .Public.refId }}: {{ .Public.error }}",
|
||||||
@@ -28,8 +25,7 @@ func MakeConversionError(refID string, err error) error {
|
|||||||
return ConversionError.Build(data)
|
return ConversionError.Build(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
var QueryError = errutil.NewBase(
|
var QueryError = errutil.BadRequest("sse.dataQueryError").MustTemplate(
|
||||||
errutil.StatusBadRequest, "sse.dataQueryError").MustTemplate(
|
|
||||||
"failed to execute query [{{ .Public.refId }}]: {{ .Error }}",
|
"failed to execute query [{{ .Public.refId }}]: {{ .Error }}",
|
||||||
errutil.WithPublic(
|
errutil.WithPublic(
|
||||||
"failed to execute query [{{ .Public.refId }}]: {{ .Public.error }}",
|
"failed to execute query [{{ .Public.refId }}]: {{ .Public.error }}",
|
||||||
|
|||||||
@@ -5,5 +5,5 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrInvalidGRN = errutil.NewBase(errutil.StatusValidationFailed, "grn.InvalidGRN")
|
ErrInvalidGRN = errutil.ValidationFailed("grn.InvalidGRN")
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -10,14 +10,12 @@ var (
|
|||||||
ErrIDTokenNotFound = errors.New("id_token not found")
|
ErrIDTokenNotFound = errors.New("id_token not found")
|
||||||
ErrEmailNotFound = errors.New("error getting user info: no email found in access token")
|
ErrEmailNotFound = errors.New("error getting user info: no email found in access token")
|
||||||
|
|
||||||
errRoleAttributePathNotSet = errutil.NewBase(errutil.StatusBadRequest,
|
errRoleAttributePathNotSet = errutil.BadRequest("oauth.role_attribute_path_not_set",
|
||||||
"oauth.role_attribute_path_not_set",
|
|
||||||
errutil.WithPublicMessage("Instance role_attribute_path misconfigured, please contact your administrator"))
|
errutil.WithPublicMessage("Instance role_attribute_path misconfigured, please contact your administrator"))
|
||||||
|
|
||||||
errRoleAttributeStrictViolation = errutil.NewBase(errutil.StatusBadRequest,
|
errRoleAttributeStrictViolation = errutil.BadRequest("oauth.role_attribute_strict_violation",
|
||||||
"oauth.role_attribute_strict_violation",
|
|
||||||
errutil.WithPublicMessage("IdP did not return a role attribute, please contact your administrator"))
|
errutil.WithPublicMessage("IdP did not return a role attribute, please contact your administrator"))
|
||||||
|
|
||||||
errInvalidRole = errutil.NewBase(errutil.StatusBadRequest, "oauth.invalid_role",
|
errInvalidRole = errutil.BadRequest("oauth.invalid_role",
|
||||||
errutil.WithPublicMessage("IdP did not return a valid role attribute, please contact your administrator"))
|
errutil.WithPublicMessage("IdP did not return a valid role attribute, please contact your administrator"))
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -33,11 +33,11 @@ type GithubTeam struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrMissingTeamMembership = errutil.NewBase(errutil.StatusUnauthorized,
|
ErrMissingTeamMembership = errutil.Unauthorized(
|
||||||
"auth.missing_team",
|
"auth.missing_team",
|
||||||
errutil.WithPublicMessage(
|
errutil.WithPublicMessage(
|
||||||
"User is not a member of one of the required teams. Please contact identity provider administrator."))
|
"User is not a member of one of the required teams. Please contact identity provider administrator."))
|
||||||
ErrMissingOrganizationMembership = errutil.NewBase(errutil.StatusUnauthorized,
|
ErrMissingOrganizationMembership = errutil.Unauthorized(
|
||||||
"auth.missing_organization",
|
"auth.missing_organization",
|
||||||
errutil.WithPublicMessage(
|
errutil.WithPublicMessage(
|
||||||
"User is not a member of one of the required organizations. Please contact identity provider administrator."))
|
"User is not a member of one of the required organizations. Please contact identity provider administrator."))
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ func Test_prepareLog(t *testing.T) {
|
|||||||
RouterLogging bool
|
RouterLogging bool
|
||||||
}
|
}
|
||||||
|
|
||||||
grafanaFlavoredErr := errutil.NewBase(errutil.StatusNotFound, "test.notFound").Errorf("got error")
|
grafanaFlavoredErr := errutil.NotFound("test.notFound").Errorf("got error")
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
|||||||
@@ -4,13 +4,14 @@ import "github.com/grafana/grafana/pkg/util/errutil"
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
// ErrPluginNotRegistered error returned when a plugin is not registered.
|
// ErrPluginNotRegistered error returned when a plugin is not registered.
|
||||||
ErrPluginNotRegistered = errutil.NewBase(errutil.StatusNotFound, "plugin.notRegistered")
|
ErrPluginNotRegistered = errutil.NotFound("plugin.notRegistered")
|
||||||
// ErrHealthCheckFailed error returned when a plugin health check failed.
|
// ErrHealthCheckFailed error returned when a plugin health check failed.
|
||||||
ErrHealthCheckFailed = errutil.NewBase(errutil.StatusInternal, "plugin.failedHealthCheck")
|
ErrHealthCheckFailed = errutil.Internal("plugin.failedHealthCheck")
|
||||||
// ErrPluginUnavailable error returned when a plugin is unavailable.
|
// ErrPluginUnavailable error returned when a plugin is unavailable.
|
||||||
ErrPluginUnavailable = errutil.NewBase(errutil.StatusInternal, "plugin.unavailable")
|
ErrPluginUnavailable = errutil.Internal("plugin.unavailable")
|
||||||
// ErrMethodNotImplemented error returned when a plugin method is not implemented.
|
// ErrMethodNotImplemented error returned when a plugin method is not implemented.
|
||||||
ErrMethodNotImplemented = errutil.NewBase(errutil.StatusNotImplemented, "plugin.notImplemented")
|
ErrMethodNotImplemented = errutil.NotImplemented("plugin.notImplemented")
|
||||||
// ErrPluginDownstreamError error returned when a plugin method is not implemented.
|
// ErrPluginDownstreamError error returned when a plugin method is not implemented.
|
||||||
ErrPluginDownstreamError = errutil.NewBase(errutil.StatusInternal, "plugin.downstreamError", errutil.WithPublicMessage("An error occurred within the plugin"))
|
ErrPluginDownstreamError = errutil.Internal("plugin.downstreamError",
|
||||||
|
errutil.WithPublicMessage("An error occurred within the plugin"))
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/util/errutil"
|
"github.com/grafana/grafana/pkg/util/errutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrInternal = errutil.NewBase(errutil.StatusInternal, "accesscontrol.internal")
|
var ErrInternal = errutil.Internal("accesscontrol.internal")
|
||||||
|
|
||||||
// RoleRegistration stores a role and its assignments to built-in roles
|
// RoleRegistration stores a role and its assignments to built-in roles
|
||||||
// (Viewer, Editor, Admin, Grafana Admin)
|
// (Viewer, Editor, Admin, Grafana Admin)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
ErrTimerangeMissing = errors.New("missing timerange")
|
ErrTimerangeMissing = errors.New("missing timerange")
|
||||||
ErrBaseTagLimitExceeded = errutil.NewBase(errutil.StatusBadRequest, "annotations.tag-limit-exceeded", errutil.WithPublicMessage("Tags length exceeds the maximum allowed."))
|
ErrBaseTagLimitExceeded = errutil.BadRequest("annotations.tag-limit-exceeded", errutil.WithPublicMessage("Tags length exceeds the maximum allowed."))
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate mockery --name Repository --structname FakeAnnotationsRepo --inpackage --filename annotations_repository_mock.go
|
//go:generate mockery --name Repository --structname FakeAnnotationsRepo --inpackage --filename annotations_repository_mock.go
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errCantAuthenticateReq = errutil.NewBase(errutil.StatusUnauthorized, "auth.unauthorized")
|
errCantAuthenticateReq = errutil.Unauthorized("auth.unauthorized")
|
||||||
errDisabledIdentity = errutil.NewBase(errutil.StatusUnauthorized, "identity.disabled")
|
errDisabledIdentity = errutil.Unauthorized("identity.disabled")
|
||||||
)
|
)
|
||||||
|
|
||||||
// make sure service implements authn.Service interface
|
// make sure service implements authn.Service interface
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errSyncPermissionsForbidden = errutil.NewBase(errutil.StatusForbidden, "permissions.sync.forbidden")
|
errSyncPermissionsForbidden = errutil.Forbidden("permissions.sync.forbidden")
|
||||||
)
|
)
|
||||||
|
|
||||||
func ProvidePermissionsSync(acService accesscontrol.Service) *PermissionsSync {
|
func ProvidePermissionsSync(acService accesscontrol.Service) *PermissionsSync {
|
||||||
|
|||||||
@@ -14,33 +14,27 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errUserSignupDisabled = errutil.NewBase(
|
errUserSignupDisabled = errutil.Unauthorized(
|
||||||
errutil.StatusUnauthorized,
|
|
||||||
"user.sync.signup-disabled",
|
"user.sync.signup-disabled",
|
||||||
errutil.WithPublicMessage("Sign up is disabled"),
|
errutil.WithPublicMessage("Sign up is disabled"),
|
||||||
)
|
)
|
||||||
errSyncUserForbidden = errutil.NewBase(
|
errSyncUserForbidden = errutil.Forbidden(
|
||||||
errutil.StatusForbidden,
|
|
||||||
"user.sync.forbidden",
|
"user.sync.forbidden",
|
||||||
errutil.WithPublicMessage("User sync forbidden"),
|
errutil.WithPublicMessage("User sync forbidden"),
|
||||||
)
|
)
|
||||||
errSyncUserInternal = errutil.NewBase(
|
errSyncUserInternal = errutil.Internal(
|
||||||
errutil.StatusInternal,
|
|
||||||
"user.sync.internal",
|
"user.sync.internal",
|
||||||
errutil.WithPublicMessage("User sync failed"),
|
errutil.WithPublicMessage("User sync failed"),
|
||||||
)
|
)
|
||||||
errUserProtection = errutil.NewBase(
|
errUserProtection = errutil.Forbidden(
|
||||||
errutil.StatusForbidden,
|
|
||||||
"user.sync.protected-role",
|
"user.sync.protected-role",
|
||||||
errutil.WithPublicMessage("Unable to sync due to protected role"),
|
errutil.WithPublicMessage("Unable to sync due to protected role"),
|
||||||
)
|
)
|
||||||
errFetchingSignedInUser = errutil.NewBase(
|
errFetchingSignedInUser = errutil.Internal(
|
||||||
errutil.StatusInternal,
|
|
||||||
"user.sync.fetch",
|
"user.sync.fetch",
|
||||||
errutil.WithPublicMessage("Insufficient information to authenticate user"),
|
errutil.WithPublicMessage("Insufficient information to authenticate user"),
|
||||||
)
|
)
|
||||||
errFetchingSignedInUserNotFound = errutil.NewBase(
|
errFetchingSignedInUserNotFound = errutil.Unauthorized(
|
||||||
errutil.StatusUnauthorized,
|
|
||||||
"user.sync.fetch-not-found",
|
"user.sync.fetch-not-found",
|
||||||
errutil.WithPublicMessage("User not found"),
|
errutil.WithPublicMessage("User not found"),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errAPIKeyInvalid = errutil.NewBase(errutil.StatusUnauthorized, "api-key.invalid", errutil.WithPublicMessage("Invalid API key"))
|
errAPIKeyInvalid = errutil.Unauthorized("api-key.invalid", errutil.WithPublicMessage("Invalid API key"))
|
||||||
errAPIKeyExpired = errutil.NewBase(errutil.StatusUnauthorized, "api-key.expired", errutil.WithPublicMessage("Expired API key"))
|
errAPIKeyExpired = errutil.Unauthorized("api-key.expired", errutil.WithPublicMessage("Expired API key"))
|
||||||
errAPIKeyRevoked = errutil.NewBase(errutil.StatusUnauthorized, "api-key.revoked", errutil.WithPublicMessage("Revoked API key"))
|
errAPIKeyRevoked = errutil.Unauthorized("api-key.revoked", errutil.WithPublicMessage("Revoked API key"))
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ authn.HookClient = new(APIKey)
|
var _ authn.HookClient = new(APIKey)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errDecodingBasicAuthHeader = errutil.NewBase(errutil.StatusBadRequest, "basic-auth.invalid-header", errutil.WithPublicMessage("Invalid Basic Auth Header"))
|
errDecodingBasicAuthHeader = errutil.BadRequest("basic-auth.invalid-header", errutil.WithPublicMessage("Invalid Basic Auth Header"))
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ authn.ContextAwareClient = new(Basic)
|
var _ authn.ContextAwareClient = new(Basic)
|
||||||
|
|||||||
@@ -9,5 +9,5 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errIdentityNotFound = errutil.NewBase(errutil.StatusNotFound, "identity.not-found")
|
errIdentityNotFound = errutil.NotFound("identity.not-found")
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errBadForm = errutil.NewBase(errutil.StatusBadRequest, "form-auth.invalid", errutil.WithPublicMessage("bad login data"))
|
errBadForm = errutil.BadRequest("form-auth.invalid", errutil.WithPublicMessage("bad login data"))
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ authn.Client = new(Form)
|
var _ authn.Client = new(Form)
|
||||||
|
|||||||
@@ -24,11 +24,11 @@ const authQueryParamName = "auth_token"
|
|||||||
var _ authn.ContextAwareClient = new(JWT)
|
var _ authn.ContextAwareClient = new(JWT)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errJWTInvalid = errutil.NewBase(errutil.StatusUnauthorized,
|
errJWTInvalid = errutil.Unauthorized(
|
||||||
"jwt.invalid", errutil.WithPublicMessage("Failed to verify JWT"))
|
"jwt.invalid", errutil.WithPublicMessage("Failed to verify JWT"))
|
||||||
errJWTMissingClaim = errutil.NewBase(errutil.StatusUnauthorized,
|
errJWTMissingClaim = errutil.Unauthorized(
|
||||||
"jwt.missing_claim", errutil.WithPublicMessage("Missing mandatory claim in JWT"))
|
"jwt.missing_claim", errutil.WithPublicMessage("Missing mandatory claim in JWT"))
|
||||||
errJWTInvalidRole = errutil.NewBase(errutil.StatusForbidden,
|
errJWTInvalidRole = errutil.Forbidden(
|
||||||
"jwt.invalid_role", errutil.WithPublicMessage("Invalid Role in claim"))
|
"jwt.invalid_role", errutil.WithPublicMessage("Invalid Role in claim"))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -35,22 +35,22 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errOAuthGenPKCE = errutil.NewBase(errutil.StatusInternal, "auth.oauth.pkce.internal", errutil.WithPublicMessage("An internal error occurred"))
|
errOAuthGenPKCE = errutil.Internal("auth.oauth.pkce.internal", errutil.WithPublicMessage("An internal error occurred"))
|
||||||
errOAuthMissingPKCE = errutil.NewBase(errutil.StatusBadRequest, "auth.oauth.pkce.missing", errutil.WithPublicMessage("Missing required pkce cookie"))
|
errOAuthMissingPKCE = errutil.BadRequest("auth.oauth.pkce.missing", errutil.WithPublicMessage("Missing required pkce cookie"))
|
||||||
|
|
||||||
errOAuthGenState = errutil.NewBase(errutil.StatusInternal, "auth.oauth.state.internal", errutil.WithPublicMessage("An internal error occurred"))
|
errOAuthGenState = errutil.Internal("auth.oauth.state.internal", errutil.WithPublicMessage("An internal error occurred"))
|
||||||
errOAuthMissingState = errutil.NewBase(errutil.StatusBadRequest, "auth.oauth.state.missing", errutil.WithPublicMessage("Missing saved oauth state"))
|
errOAuthMissingState = errutil.BadRequest("auth.oauth.state.missing", errutil.WithPublicMessage("Missing saved oauth state"))
|
||||||
errOAuthInvalidState = errutil.NewBase(errutil.StatusUnauthorized, "auth.oauth.state.invalid", errutil.WithPublicMessage("Provided state does not match stored state"))
|
errOAuthInvalidState = errutil.Unauthorized("auth.oauth.state.invalid", errutil.WithPublicMessage("Provided state does not match stored state"))
|
||||||
|
|
||||||
errOAuthTokenExchange = errutil.NewBase(errutil.StatusInternal, "auth.oauth.token.exchange", errutil.WithPublicMessage("Failed to get token from provider"))
|
errOAuthTokenExchange = errutil.Internal("auth.oauth.token.exchange", errutil.WithPublicMessage("Failed to get token from provider"))
|
||||||
errOAuthUserInfo = errutil.NewBase(errutil.StatusInternal, "auth.oauth.userinfo.error")
|
errOAuthUserInfo = errutil.Internal("auth.oauth.userinfo.error")
|
||||||
|
|
||||||
errOAuthMissingRequiredEmail = errutil.NewBase(errutil.StatusUnauthorized, "auth.oauth.email.missing", errutil.WithPublicMessage("Provider didn't return an email address"))
|
errOAuthMissingRequiredEmail = errutil.Unauthorized("auth.oauth.email.missing", errutil.WithPublicMessage("Provider didn't return an email address"))
|
||||||
errOAuthEmailNotAllowed = errutil.NewBase(errutil.StatusUnauthorized, "auth.oauth.email.not-allowed", errutil.WithPublicMessage("Required email domain not fulfilled"))
|
errOAuthEmailNotAllowed = errutil.Unauthorized("auth.oauth.email.not-allowed", errutil.WithPublicMessage("Required email domain not fulfilled"))
|
||||||
)
|
)
|
||||||
|
|
||||||
func fromSocialErr(err *social.Error) error {
|
func fromSocialErr(err *social.Error) error {
|
||||||
return errutil.NewBase(errutil.StatusUnauthorized, "auth.oauth.userinfo.failed", errutil.WithPublicMessage(err.Error())).Errorf("%w", err)
|
return errutil.Unauthorized("auth.oauth.userinfo.failed", errutil.WithPublicMessage(err.Error())).Errorf("%w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ authn.RedirectClient = new(OAuth)
|
var _ authn.RedirectClient = new(OAuth)
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errEmptyPassword = errutil.NewBase(errutil.StatusUnauthorized, "password-auth.empty", errutil.WithPublicMessage("Invalid username or password"))
|
errEmptyPassword = errutil.Unauthorized("password-auth.empty", errutil.WithPublicMessage("Invalid username or password"))
|
||||||
errPasswordAuthFailed = errutil.NewBase(errutil.StatusUnauthorized, "password-auth.failed", errutil.WithPublicMessage("Invalid username or password"))
|
errPasswordAuthFailed = errutil.Unauthorized("password-auth.failed", errutil.WithPublicMessage("Invalid username or password"))
|
||||||
errInvalidPassword = errutil.NewBase(errutil.StatusUnauthorized, "password-auth.invalid", errutil.WithPublicMessage("Invalid password or username"))
|
errInvalidPassword = errutil.Unauthorized("password-auth.invalid", errutil.WithPublicMessage("Invalid password or username"))
|
||||||
errLoginAttemptBlocked = errutil.NewBase(errutil.StatusUnauthorized, "login-attempt.blocked", errutil.WithPublicMessage("Invalid username or password"))
|
errLoginAttemptBlocked = errutil.Unauthorized("login-attempt.blocked", errutil.WithPublicMessage("Invalid username or password"))
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ authn.PasswordClient = new(Password)
|
var _ authn.PasswordClient = new(Password)
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ const (
|
|||||||
var proxyFields = [...]string{proxyFieldName, proxyFieldEmail, proxyFieldLogin, proxyFieldRole, proxyFieldGroups}
|
var proxyFields = [...]string{proxyFieldName, proxyFieldEmail, proxyFieldLogin, proxyFieldRole, proxyFieldGroups}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errNotAcceptedIP = errutil.NewBase(errutil.StatusUnauthorized, "auth-proxy.invalid-ip")
|
errNotAcceptedIP = errutil.Unauthorized("auth-proxy.invalid-ip")
|
||||||
errEmptyProxyHeader = errutil.NewBase(errutil.StatusUnauthorized, "auth-proxy.empty-header")
|
errEmptyProxyHeader = errutil.Unauthorized("auth-proxy.empty-header")
|
||||||
errInvalidProxyHeader = errutil.NewBase(errutil.StatusInternal, "auth-proxy.invalid-proxy-header")
|
errInvalidProxyHeader = errutil.Internal("auth-proxy.invalid-proxy-header")
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errInvalidRenderKey = errutil.NewBase(errutil.StatusUnauthorized, "render-auth.invalid-key", errutil.WithPublicMessage("Invalid Render Key"))
|
errInvalidRenderKey = errutil.Unauthorized("render-auth.invalid-key", errutil.WithPublicMessage("Invalid Render Key"))
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package authn
|
|||||||
import "github.com/grafana/grafana/pkg/util/errutil"
|
import "github.com/grafana/grafana/pkg/util/errutil"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrTokenNeedsRotation = errutil.NewBase(errutil.StatusUnauthorized, "session.token.rotate")
|
ErrTokenNeedsRotation = errutil.Unauthorized("session.token.rotate")
|
||||||
ErrUnsupportedClient = errutil.NewBase(errutil.StatusBadRequest, "auth.client.unsupported")
|
ErrUnsupportedClient = errutil.BadRequest("auth.client.unsupported")
|
||||||
ErrClientNotConfigured = errutil.NewBase(errutil.StatusBadRequest, "auth.client.notConfigured")
|
ErrClientNotConfigured = errutil.BadRequest("auth.client.notConfigured")
|
||||||
ErrUnsupportedIdentity = errutil.NewBase(errutil.StatusNotImplemented, "auth.identity.unsupported")
|
ErrUnsupportedIdentity = errutil.NotImplemented("auth.identity.unsupported")
|
||||||
ErrExpiredAccessToken = errutil.NewBase(errutil.StatusUnauthorized, "oauth.expired-token", errutil.WithPublicMessage("OAuth access token expired"))
|
ErrExpiredAccessToken = errutil.Unauthorized("oauth.expired-token", errutil.WithPublicMessage("OAuth access token expired"))
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4,4 +4,4 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/util/errutil"
|
"github.com/grafana/grafana/pkg/util/errutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrBaseNotFound = errutil.NewBase(errutil.StatusNotFound, "dashboardsnapshots.not-found", errutil.WithPublicMessage("Snapshot not found"))
|
var ErrBaseNotFound = errutil.NotFound("dashboardsnapshots.not-found", errutil.WithPublicMessage("Snapshot not found"))
|
||||||
|
|||||||
@@ -15,6 +15,6 @@ var (
|
|||||||
ErrDataSourceFailedGenerateUniqueUid = errors.New("failed to generate unique datasource ID")
|
ErrDataSourceFailedGenerateUniqueUid = errors.New("failed to generate unique datasource ID")
|
||||||
ErrDataSourceIdentifierNotSet = errors.New("unique identifier and org id are needed to be able to get or delete a datasource")
|
ErrDataSourceIdentifierNotSet = errors.New("unique identifier and org id are needed to be able to get or delete a datasource")
|
||||||
ErrDatasourceIsReadOnly = errors.New("data source is readonly, can only be updated from configuration")
|
ErrDatasourceIsReadOnly = errors.New("data source is readonly, can only be updated from configuration")
|
||||||
ErrDataSourceNameInvalid = errutil.NewBase(errutil.StatusValidationFailed, "datasource.nameInvalid", errutil.WithPublicMessage("Invalid datasource name."))
|
ErrDataSourceNameInvalid = errutil.ValidationFailed("datasource.nameInvalid", errutil.WithPublicMessage("Invalid datasource name."))
|
||||||
ErrDataSourceURLInvalid = errutil.NewBase(errutil.StatusValidationFailed, "datasource.urlInvalid", errutil.WithPublicMessage("Invalid datasource url."))
|
ErrDataSourceURLInvalid = errutil.ValidationFailed("datasource.urlInvalid", errutil.WithPublicMessage("Invalid datasource url."))
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/util/errutil"
|
"github.com/grafana/grafana/pkg/util/errutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrMaximumDepthReached = errutil.NewBase(errutil.StatusBadRequest, "folder.maximum-depth-reached", errutil.WithPublicMessage("Maximum nested folder depth reached"))
|
var ErrMaximumDepthReached = errutil.BadRequest("folder.maximum-depth-reached", errutil.WithPublicMessage("Maximum nested folder depth reached"))
|
||||||
var ErrBadRequest = errutil.NewBase(errutil.StatusBadRequest, "folder.bad-request")
|
var ErrBadRequest = errutil.BadRequest("folder.bad-request")
|
||||||
var ErrDatabaseError = errutil.NewBase(errutil.StatusInternal, "folder.database-error")
|
var ErrDatabaseError = errutil.Internal("folder.database-error")
|
||||||
var ErrInternal = errutil.NewBase(errutil.StatusInternal, "folder.internal")
|
var ErrInternal = errutil.Internal("folder.internal")
|
||||||
var ErrCircularReference = errutil.NewBase(errutil.StatusBadRequest, "folder.circular-reference", errutil.WithPublicMessage("Circular reference detected"))
|
var ErrCircularReference = errutil.BadRequest("folder.circular-reference", errutil.WithPublicMessage("Circular reference detected"))
|
||||||
var ErrTargetRegistrySrvConflict = errutil.NewBase(errutil.StatusInternal, "folder.target-registry-srv-conflict")
|
var ErrTargetRegistrySrvConflict = errutil.Internal("folder.target-registry-srv-conflict")
|
||||||
|
|
||||||
const (
|
const (
|
||||||
GeneralFolderUID = "general"
|
GeneralFolderUID = "general"
|
||||||
@@ -23,7 +23,7 @@ const (
|
|||||||
MaxNestedFolderDepth = 8
|
MaxNestedFolderDepth = 8
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrFolderNotFound = errutil.NewBase(errutil.StatusNotFound, "folder.notFound")
|
var ErrFolderNotFound = errutil.NotFound("folder.notFound")
|
||||||
|
|
||||||
type Folder struct {
|
type Folder struct {
|
||||||
ID int64 `xorm:"pk autoincr 'id'"`
|
ID int64 `xorm:"pk autoincr 'id'"`
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ import (
|
|||||||
var (
|
var (
|
||||||
ErrGuardianPermissionExists = errors.New("permission already exists")
|
ErrGuardianPermissionExists = errors.New("permission already exists")
|
||||||
ErrGuardianOverride = errors.New("you can only override a permission to be higher")
|
ErrGuardianOverride = errors.New("you can only override a permission to be higher")
|
||||||
ErrGuardianGetDashboardFailure = errutil.NewBase(errutil.StatusInternal, "guardian.getDashboardFailure", errutil.WithPublicMessage("Failed to get dashboard"))
|
ErrGuardianGetDashboardFailure = errutil.Internal("guardian.getDashboardFailure", errutil.WithPublicMessage("Failed to get dashboard"))
|
||||||
ErrGuardianGetFolderFailure = errutil.NewBase(errutil.StatusInternal, "guardian.getFolderFailure", errutil.WithPublicMessage("Failed to get folder"))
|
ErrGuardianGetFolderFailure = errutil.Internal("guardian.getFolderFailure", errutil.WithPublicMessage("Failed to get folder"))
|
||||||
ErrGuardianDashboardNotFound = errutil.NewBase(errutil.StatusNotFound, "guardian.dashboardNotFound")
|
ErrGuardianDashboardNotFound = errutil.NotFound("guardian.dashboardNotFound")
|
||||||
ErrGuardianFolderNotFound = errutil.NewBase(errutil.StatusNotFound, "guardian.folderNotFound")
|
ErrGuardianFolderNotFound = errutil.NotFound("guardian.folderNotFound")
|
||||||
)
|
)
|
||||||
|
|
||||||
// DashboardGuardian to be used for guard against operations without access on dashboard and acl
|
// DashboardGuardian to be used for guard against operations without access on dashboard and acl
|
||||||
|
|||||||
@@ -11,16 +11,16 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrClientRequiredID = errutil.NewBase(errutil.StatusBadRequest,
|
ErrClientRequiredID = errutil.BadRequest(
|
||||||
"oauthserver.required-client-id",
|
"oauthserver.required-client-id",
|
||||||
errutil.WithPublicMessage("client ID is required")).Errorf("Client ID is required")
|
errutil.WithPublicMessage("client ID is required")).Errorf("Client ID is required")
|
||||||
ErrClientRequiredName = errutil.NewBase(errutil.StatusBadRequest,
|
ErrClientRequiredName = errutil.BadRequest(
|
||||||
"oauthserver.required-client-name",
|
"oauthserver.required-client-name",
|
||||||
errutil.WithPublicMessage("client name is required")).Errorf("Client name is required")
|
errutil.WithPublicMessage("client name is required")).Errorf("Client name is required")
|
||||||
)
|
)
|
||||||
|
|
||||||
func ErrClientNotFound(clientID string) error {
|
func ErrClientNotFound(clientID string) error {
|
||||||
return errutil.NewBase(errutil.StatusNotFound,
|
return errutil.NotFound(
|
||||||
ErrClientNotFoundMessageID,
|
ErrClientNotFoundMessageID,
|
||||||
errutil.WithPublicMessage(fmt.Sprintf("Client '%s' not found", clientID))).
|
errutil.WithPublicMessage(fmt.Sprintf("Client '%s' not found", clientID))).
|
||||||
Errorf("client '%s' not found", clientID)
|
Errorf("client '%s' not found", clientID)
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ var (
|
|||||||
ErrLastOrgAdmin = errors.New("cannot remove last organization admin")
|
ErrLastOrgAdmin = errors.New("cannot remove last organization admin")
|
||||||
ErrOrgUserNotFound = errors.New("cannot find the organization user")
|
ErrOrgUserNotFound = errors.New("cannot find the organization user")
|
||||||
ErrOrgUserAlreadyAdded = errors.New("user is already added to organization")
|
ErrOrgUserAlreadyAdded = errors.New("user is already added to organization")
|
||||||
ErrOrgNotFound = errutil.NewBase(errutil.StatusNotFound, "org.notFound", errutil.WithPublicMessage("organization not found"))
|
ErrOrgNotFound = errutil.NotFound("org.notFound", errutil.WithPublicMessage("organization not found"))
|
||||||
ErrCannotChangeRoleForExternallySyncedUser = errutil.NewBase(errutil.StatusForbidden, "org.externallySynced", errutil.WithPublicMessage("cannot change role for externally synced user"))
|
ErrCannotChangeRoleForExternallySyncedUser = errutil.Forbidden("org.externallySynced", errutil.WithPublicMessage("cannot change role for externally synced user"))
|
||||||
)
|
)
|
||||||
|
|
||||||
type Org struct {
|
type Org struct {
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var ErrPrefNotFound = errors.New("preference not found")
|
var ErrPrefNotFound = errors.New("preference not found")
|
||||||
var ErrUnknownCookieType = errutil.NewBase(
|
var ErrUnknownCookieType = errutil.BadRequest(
|
||||||
errutil.StatusBadRequest,
|
|
||||||
"preferences.unknownCookieType",
|
"preferences.unknownCookieType",
|
||||||
errutil.WithPublicMessage("Got an unknown cookie preference type. Expected a set containing one or more of 'functional', 'performance', or 'analytics'}"),
|
errutil.WithPublicMessage("Got an unknown cookie preference type. Expected a set containing one or more of 'functional', 'performance', or 'analytics'}"),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,24 +3,24 @@ package models
|
|||||||
import "github.com/grafana/grafana/pkg/util/errutil"
|
import "github.com/grafana/grafana/pkg/util/errutil"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrInternalServerError = errutil.NewBase(errutil.StatusInternal, "publicdashboards.internalServerError", errutil.WithPublicMessage("Internal server error"))
|
ErrInternalServerError = errutil.Internal("publicdashboards.internalServerError", errutil.WithPublicMessage("Internal server error"))
|
||||||
|
|
||||||
ErrPublicDashboardNotFound = errutil.NewBase(errutil.StatusNotFound, "publicdashboards.notFound", errutil.WithPublicMessage("Public dashboard not found"))
|
ErrPublicDashboardNotFound = errutil.NotFound("publicdashboards.notFound", errutil.WithPublicMessage("Public dashboard not found"))
|
||||||
ErrDashboardNotFound = errutil.NewBase(errutil.StatusNotFound, "publicdashboards.dashboardNotFound", errutil.WithPublicMessage("Dashboard not found"))
|
ErrDashboardNotFound = errutil.NotFound("publicdashboards.dashboardNotFound", errutil.WithPublicMessage("Dashboard not found"))
|
||||||
ErrPanelNotFound = errutil.NewBase(errutil.StatusNotFound, "publicdashboards.panelNotFound", errutil.WithPublicMessage("Public dashboard panel not found"))
|
ErrPanelNotFound = errutil.NotFound("publicdashboards.panelNotFound", errutil.WithPublicMessage("Public dashboard panel not found"))
|
||||||
|
|
||||||
ErrBadRequest = errutil.NewBase(errutil.StatusBadRequest, "publicdashboards.badRequest")
|
ErrBadRequest = errutil.BadRequest("publicdashboards.badRequest")
|
||||||
ErrPanelQueriesNotFound = errutil.NewBase(errutil.StatusBadRequest, "publicdashboards.panelQueriesNotFound", errutil.WithPublicMessage("Failed to extract queries from panel"))
|
ErrPanelQueriesNotFound = errutil.BadRequest("publicdashboards.panelQueriesNotFound", errutil.WithPublicMessage("Failed to extract queries from panel"))
|
||||||
ErrInvalidAccessToken = errutil.NewBase(errutil.StatusBadRequest, "publicdashboards.invalidAccessToken", errutil.WithPublicMessage("Invalid access token"))
|
ErrInvalidAccessToken = errutil.BadRequest("publicdashboards.invalidAccessToken", errutil.WithPublicMessage("Invalid access token"))
|
||||||
ErrInvalidPanelId = errutil.NewBase(errutil.StatusBadRequest, "publicdashboards.invalidPanelId", errutil.WithPublicMessage("Invalid panel id"))
|
ErrInvalidPanelId = errutil.BadRequest("publicdashboards.invalidPanelId", errutil.WithPublicMessage("Invalid panel id"))
|
||||||
ErrInvalidUid = errutil.NewBase(errutil.StatusBadRequest, "publicdashboards.invalidUid", errutil.WithPublicMessage("Invalid Uid"))
|
ErrInvalidUid = errutil.BadRequest("publicdashboards.invalidUid", errutil.WithPublicMessage("Invalid Uid"))
|
||||||
ErrPublicDashboardIdentifierNotSet = errutil.NewBase(errutil.StatusBadRequest, "publicdashboards.identifierNotSet", errutil.WithPublicMessage("No Uid for public dashboard specified"))
|
ErrPublicDashboardIdentifierNotSet = errutil.BadRequest("publicdashboards.identifierNotSet", errutil.WithPublicMessage("No Uid for public dashboard specified"))
|
||||||
ErrPublicDashboardHasTemplateVariables = errutil.NewBase(errutil.StatusBadRequest, "publicdashboards.hasTemplateVariables", errutil.WithPublicMessage("Public dashboard has template variables"))
|
ErrPublicDashboardHasTemplateVariables = errutil.BadRequest("publicdashboards.hasTemplateVariables", errutil.WithPublicMessage("Public dashboard has template variables"))
|
||||||
ErrInvalidInterval = errutil.NewBase(errutil.StatusBadRequest, "publicdashboards.invalidInterval", errutil.WithPublicMessage("intervalMS should be greater than 0"))
|
ErrInvalidInterval = errutil.BadRequest("publicdashboards.invalidInterval", errutil.WithPublicMessage("intervalMS should be greater than 0"))
|
||||||
ErrInvalidMaxDataPoints = errutil.NewBase(errutil.StatusBadRequest, "publicdashboards.maxDataPoints", errutil.WithPublicMessage("maxDataPoints should be greater than 0"))
|
ErrInvalidMaxDataPoints = errutil.BadRequest("publicdashboards.maxDataPoints", errutil.WithPublicMessage("maxDataPoints should be greater than 0"))
|
||||||
ErrInvalidTimeRange = errutil.NewBase(errutil.StatusBadRequest, "publicdashboards.invalidTimeRange", errutil.WithPublicMessage("Invalid time range"))
|
ErrInvalidTimeRange = errutil.BadRequest("publicdashboards.invalidTimeRange", errutil.WithPublicMessage("Invalid time range"))
|
||||||
ErrInvalidShareType = errutil.NewBase(errutil.StatusBadRequest, "publicdashboards.invalidShareType", errutil.WithPublicMessage("Invalid share type"))
|
ErrInvalidShareType = errutil.BadRequest("publicdashboards.invalidShareType", errutil.WithPublicMessage("Invalid share type"))
|
||||||
ErrDashboardIsPublic = errutil.NewBase(errutil.StatusBadRequest, "publicdashboards.dashboardIsPublic", errutil.WithPublicMessage("Dashboard is already public"))
|
ErrDashboardIsPublic = errutil.BadRequest("publicdashboards.dashboardIsPublic", errutil.WithPublicMessage("Dashboard is already public"))
|
||||||
|
|
||||||
ErrPublicDashboardNotEnabled = errutil.NewBase(errutil.StatusForbidden, "publicdashboards.notEnabled", errutil.WithPublicMessage("Public dashboard paused"))
|
ErrPublicDashboardNotEnabled = errutil.Forbidden("publicdashboards.notEnabled", errutil.WithPublicMessage("Public dashboard paused"))
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrNoQueriesFound = errutil.NewBase(errutil.StatusBadRequest, "query.noQueries", errutil.WithPublicMessage("No queries found")).Errorf("no queries found")
|
ErrNoQueriesFound = errutil.BadRequest("query.noQueries", errutil.WithPublicMessage("No queries found")).Errorf("no queries found")
|
||||||
ErrInvalidDatasourceID = errutil.NewBase(errutil.StatusBadRequest, "query.invalidDatasourceId", errutil.WithPublicMessage("Query does not contain a valid data source identifier")).Errorf("invalid data source identifier")
|
ErrInvalidDatasourceID = errutil.BadRequest("query.invalidDatasourceId", errutil.WithPublicMessage("Query does not contain a valid data source identifier")).Errorf("invalid data source identifier")
|
||||||
ErrMissingDataSourceInfo = errutil.NewBase(errutil.StatusBadRequest, "query.missingDataSourceInfo").MustTemplate("query missing datasource info: {{ .Public.RefId }}", errutil.WithPublic("Query {{ .Public.RefId }} is missing datasource information"))
|
ErrMissingDataSourceInfo = errutil.BadRequest("query.missingDataSourceInfo").MustTemplate("query missing datasource info: {{ .Public.RefId }}", errutil.WithPublic("Query {{ .Public.RefId }} is missing datasource information"))
|
||||||
ErrQueryParamMismatch = errutil.NewBase(errutil.StatusBadRequest, "query.headerMismatch", errutil.WithPublicMessage("The request headers point to a different plugin than is defined in the request body")).Errorf("plugin header/body mismatch")
|
ErrQueryParamMismatch = errutil.BadRequest("query.headerMismatch", errutil.WithPublicMessage("The request headers point to a different plugin than is defined in the request body")).Errorf("plugin header/body mismatch")
|
||||||
ErrDuplicateRefId = errutil.NewBase(errutil.StatusBadRequest, "query.duplicateRefId", errutil.WithPublicMessage("Multiple queries using the same RefId is not allowed ")).Errorf("multiple queries using the same RefId is not allowed")
|
ErrDuplicateRefId = errutil.BadRequest("query.duplicateRefId", errutil.WithPublicMessage("Multiple queries using the same RefId is not allowed ")).Errorf("multiple queries using the same RefId is not allowed")
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,15 +8,15 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/util/errutil"
|
"github.com/grafana/grafana/pkg/util/errutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrBadRequest = errutil.NewBase(errutil.StatusBadRequest, "quota.bad-request")
|
var ErrBadRequest = errutil.BadRequest("quota.bad-request")
|
||||||
var ErrInvalidTargetSrv = errutil.NewBase(errutil.StatusBadRequest, "quota.invalid-target")
|
var ErrInvalidTargetSrv = errutil.BadRequest("quota.invalid-target")
|
||||||
var ErrInvalidScope = errutil.NewBase(errutil.StatusBadRequest, "quota.invalid-scope")
|
var ErrInvalidScope = errutil.BadRequest("quota.invalid-scope")
|
||||||
var ErrFailedToGetScope = errutil.NewBase(errutil.StatusInternal, "quota.failed-get-scope")
|
var ErrFailedToGetScope = errutil.Internal("quota.failed-get-scope")
|
||||||
var ErrInvalidTarget = errutil.NewBase(errutil.StatusInternal, "quota.invalid-target-table")
|
var ErrInvalidTarget = errutil.Internal("quota.invalid-target-table")
|
||||||
var ErrUsageFoundForTarget = errutil.NewBase(errutil.StatusNotFound, "quota.missing-target-usage")
|
var ErrUsageFoundForTarget = errutil.NotFound("quota.missing-target-usage")
|
||||||
var ErrTargetSrvConflict = errutil.NewBase(errutil.StatusBadRequest, "quota.target-srv-conflict")
|
var ErrTargetSrvConflict = errutil.BadRequest("quota.target-srv-conflict")
|
||||||
var ErrDisabled = errutil.NewBase(errutil.StatusForbidden, "quota.disabled", errutil.WithPublicMessage("Quotas not enabled"))
|
var ErrDisabled = errutil.Forbidden("quota.disabled", errutil.WithPublicMessage("Quotas not enabled"))
|
||||||
var ErrInvalidTagFormat = errutil.NewBase(errutil.StatusInternal, "quota.invalid-invalid-tag-format")
|
var ErrInvalidTagFormat = errutil.Internal("quota.invalid-invalid-tag-format")
|
||||||
|
|
||||||
type ScopeParameters struct {
|
type ScopeParameters struct {
|
||||||
OrgID int64
|
OrgID int64
|
||||||
|
|||||||
@@ -24,17 +24,17 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrServiceAccountNotFound = errutil.NewBase(errutil.StatusNotFound, "serviceaccounts.ErrNotFound", errutil.WithPublicMessage("service account not found"))
|
ErrServiceAccountNotFound = errutil.NotFound("serviceaccounts.ErrNotFound", errutil.WithPublicMessage("service account not found"))
|
||||||
ErrServiceAccountInvalidRole = errutil.NewBase(errutil.StatusBadRequest, "serviceaccounts.ErrInvalidRoleSpecified", errutil.WithPublicMessage("invalid role specified"))
|
ErrServiceAccountInvalidRole = errutil.BadRequest("serviceaccounts.ErrInvalidRoleSpecified", errutil.WithPublicMessage("invalid role specified"))
|
||||||
ErrServiceAccountRolePrivilegeDenied = errutil.NewBase(errutil.StatusForbidden, "serviceaccounts.ErrRoleForbidden", errutil.WithPublicMessage("can not assign a role higher than user's role"))
|
ErrServiceAccountRolePrivilegeDenied = errutil.Forbidden("serviceaccounts.ErrRoleForbidden", errutil.WithPublicMessage("can not assign a role higher than user's role"))
|
||||||
ErrServiceAccountInvalidOrgID = errutil.NewBase(errutil.StatusBadRequest, "serviceaccounts.ErrInvalidOrgId", errutil.WithPublicMessage("invalid org id specified"))
|
ErrServiceAccountInvalidOrgID = errutil.BadRequest("serviceaccounts.ErrInvalidOrgId", errutil.WithPublicMessage("invalid org id specified"))
|
||||||
ErrServiceAccountInvalidID = errutil.NewBase(errutil.StatusBadRequest, "serviceaccounts.ErrInvalidId", errutil.WithPublicMessage("invalid service account id specified"))
|
ErrServiceAccountInvalidID = errutil.BadRequest("serviceaccounts.ErrInvalidId", errutil.WithPublicMessage("invalid service account id specified"))
|
||||||
ErrServiceAccountInvalidAPIKeyID = errutil.NewBase(errutil.StatusBadRequest, "serviceaccounts.ErrInvalidAPIKeyId", errutil.WithPublicMessage("invalid api key id specified"))
|
ErrServiceAccountInvalidAPIKeyID = errutil.BadRequest("serviceaccounts.ErrInvalidAPIKeyId", errutil.WithPublicMessage("invalid api key id specified"))
|
||||||
ErrServiceAccountInvalidTokenID = errutil.NewBase(errutil.StatusBadRequest, "serviceaccounts.ErrInvalidTokenId", errutil.WithPublicMessage("invalid service account token id specified"))
|
ErrServiceAccountInvalidTokenID = errutil.BadRequest("serviceaccounts.ErrInvalidTokenId", errutil.WithPublicMessage("invalid service account token id specified"))
|
||||||
ErrServiceAccountAlreadyExists = errutil.NewBase(errutil.StatusBadRequest, "serviceaccounts.ErrAlreadyExists", errutil.WithPublicMessage("service account already exists"))
|
ErrServiceAccountAlreadyExists = errutil.BadRequest("serviceaccounts.ErrAlreadyExists", errutil.WithPublicMessage("service account already exists"))
|
||||||
ErrServiceAccountTokenNotFound = errutil.NewBase(errutil.StatusNotFound, "serviceaccounts.ErrTokenNotFound", errutil.WithPublicMessage("service account token not found"))
|
ErrServiceAccountTokenNotFound = errutil.NotFound("serviceaccounts.ErrTokenNotFound", errutil.WithPublicMessage("service account token not found"))
|
||||||
ErrInvalidTokenExpiration = errutil.NewBase(errutil.StatusValidationFailed, "serviceaccounts.ErrInvalidInput", errutil.WithPublicMessage("invalid SecondsToLive value"))
|
ErrInvalidTokenExpiration = errutil.ValidationFailed("serviceaccounts.ErrInvalidInput", errutil.WithPublicMessage("invalid SecondsToLive value"))
|
||||||
ErrDuplicateToken = errutil.NewBase(errutil.StatusBadRequest, "serviceaccounts.ErrTokenAlreadyExists", errutil.WithPublicMessage("service account token with given name already exists in the organization"))
|
ErrDuplicateToken = errutil.BadRequest("serviceaccounts.ErrTokenAlreadyExists", errutil.WithPublicMessage("service account token with given name already exists in the organization"))
|
||||||
)
|
)
|
||||||
|
|
||||||
type MigrationResult struct {
|
type MigrationResult struct {
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrShortURLBadRequest = errutil.NewBase(errutil.StatusBadRequest, "shorturl.bad-request")
|
ErrShortURLBadRequest = errutil.BadRequest("shorturl.bad-request")
|
||||||
ErrShortURLNotFound = errutil.NewBase(errutil.StatusNotFound, "shorturl.not-found")
|
ErrShortURLNotFound = errutil.NotFound("shorturl.not-found")
|
||||||
ErrShortURLAbsolutePath = errutil.NewBase(errutil.StatusValidationFailed, "shorturl.absolute-path", errutil.WithPublicMessage("Path should be relative"))
|
ErrShortURLAbsolutePath = errutil.ValidationFailed("shorturl.absolute-path", errutil.WithPublicMessage("Path should be relative"))
|
||||||
ErrShortURLInvalidPath = errutil.NewBase(errutil.StatusValidationFailed, "shorturl.invalid-path", errutil.WithPublicMessage("Invalid short URL path"))
|
ErrShortURLInvalidPath = errutil.ValidationFailed("shorturl.invalid-path", errutil.WithPublicMessage("Invalid short URL path"))
|
||||||
ErrShortURLInternal = errutil.NewBase(errutil.StatusInternal, "shorturl.internal")
|
ErrShortURLInternal = errutil.Internal("shorturl.internal")
|
||||||
)
|
)
|
||||||
|
|
||||||
type ShortUrl struct {
|
type ShortUrl struct {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package signingkeys
|
|||||||
import "github.com/grafana/grafana/pkg/util/errutil"
|
import "github.com/grafana/grafana/pkg/util/errutil"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrSigningKeyNotFound = errutil.NewBase(errutil.StatusNotFound, "signingkeys.keyNotFound")
|
ErrSigningKeyNotFound = errutil.NotFound("signingkeys.keyNotFound")
|
||||||
ErrSigningKeyAlreadyExists = errutil.NewBase(errutil.StatusBadRequest, "signingkeys.keyAlreadyExists")
|
ErrSigningKeyAlreadyExists = errutil.BadRequest("signingkeys.keyAlreadyExists")
|
||||||
ErrKeyGenerationFailed = errutil.NewBase(errutil.StatusInternal, "signingkeys.keyGenerationFailed")
|
ErrKeyGenerationFailed = errutil.Internal("signingkeys.keyGenerationFailed")
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var sessionLogger = log.New("sqlstore.session")
|
var sessionLogger = log.New("sqlstore.session")
|
||||||
var ErrMaximumRetriesReached = errutil.NewBase(errutil.StatusInternal, "sqlstore.max-retries-reached")
|
var ErrMaximumRetriesReached = errutil.Internal("sqlstore.max-retries-reached")
|
||||||
|
|
||||||
type DBSession struct {
|
type DBSession struct {
|
||||||
*xorm.Session
|
*xorm.Session
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ var XormDriverMu sync.RWMutex
|
|||||||
// MetaKeyExecutedQueryString is the key where the executed query should get stored
|
// MetaKeyExecutedQueryString is the key where the executed query should get stored
|
||||||
const MetaKeyExecutedQueryString = "executedQueryString"
|
const MetaKeyExecutedQueryString = "executedQueryString"
|
||||||
|
|
||||||
var ErrConnectionFailed = errutil.NewBase(errutil.StatusInternal, "sqleng.connectionError")
|
var ErrConnectionFailed = errutil.Internal("sqleng.connectionError")
|
||||||
|
|
||||||
// SQLMacroEngine interpolates macros into sql. It takes in the Query to have access to query context and
|
// SQLMacroEngine interpolates macros into sql. It takes in the Query to have access to query context and
|
||||||
// timeRange to be able to generate queries that use from and to.
|
// timeRange to be able to generate queries that use from and to.
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/util/errutil"
|
"github.com/grafana/grafana/pkg/util/errutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrNonGrafanaError = errutil.NewBase(errutil.StatusInternal, "core.MalformedError")
|
var ErrNonGrafanaError = errutil.Internal("core.MalformedError")
|
||||||
var defaultLogger = log.New("requestErrors")
|
var defaultLogger = log.New("requestErrors")
|
||||||
|
|
||||||
// ErrorOptions is a container for functional options passed to [Write].
|
// ErrorOptions is a container for functional options passed to [Write].
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
func TestWrite(t *testing.T) {
|
func TestWrite(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
const msgID = "test.thisIsExpected"
|
const msgID = "test.thisIsExpected"
|
||||||
base := errutil.NewBase(errutil.StatusTimeout, msgID)
|
base := errutil.Timeout(msgID)
|
||||||
handler := func(writer http.ResponseWriter, request *http.Request) {
|
handler := func(writer http.ResponseWriter, request *http.Request) {
|
||||||
Write(ctx, base.Errorf("got expected error"), writer)
|
Write(ctx, base.Errorf("got expected error"), writer)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,108 @@ func NewBase(reason StatusReason, msgID string, opts ...BaseOpt) Base {
|
|||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NotFound initializes a new [Base] error with reason StatusNotFound
|
||||||
|
// that is used to construct [Error]. The msgID is passed to the caller
|
||||||
|
// to serve as the base for user facing error messages.
|
||||||
|
//
|
||||||
|
// msgID should be structured as component.errorBrief, for example
|
||||||
|
//
|
||||||
|
// folder.notFound
|
||||||
|
// plugin.notRegistered
|
||||||
|
func NotFound(msgID string, opts ...BaseOpt) Base {
|
||||||
|
return NewBase(StatusNotFound, msgID, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BadRequest initializes a new [Base] error with reason StatusBadRequest
|
||||||
|
// that is used to construct [Error]. The msgID is passed to the caller
|
||||||
|
// to serve as the base for user facing error messages.
|
||||||
|
//
|
||||||
|
// msgID should be structured as component.errorBrief, for example
|
||||||
|
//
|
||||||
|
// query.invalidDatasourceId
|
||||||
|
// sse.dataQueryError
|
||||||
|
func BadRequest(msgID string, opts ...BaseOpt) Base {
|
||||||
|
return NewBase(StatusBadRequest, msgID, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidationFailed initializes a new [Base] error with reason StatusValidationFailed
|
||||||
|
// that is used to construct [Error]. The msgID is passed to the caller
|
||||||
|
// to serve as the base for user facing error messages.
|
||||||
|
//
|
||||||
|
// msgID should be structured as component.errorBrief, for example
|
||||||
|
//
|
||||||
|
// datasource.nameInvalid
|
||||||
|
// datasource.urlInvalid
|
||||||
|
// serviceaccounts.errInvalidInput
|
||||||
|
func ValidationFailed(msgID string, opts ...BaseOpt) Base {
|
||||||
|
return NewBase(StatusValidationFailed, msgID, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Internal initializes a new [Base] error with reason StatusInternal
|
||||||
|
// that is used to construct [Error]. The msgID is passed to the caller
|
||||||
|
// to serve as the base for user facing error messages.
|
||||||
|
//
|
||||||
|
// msgID should be structured as component.errorBrief, for example
|
||||||
|
//
|
||||||
|
// sqleng.connectionError
|
||||||
|
// plugin.downstreamError
|
||||||
|
func Internal(msgID string, opts ...BaseOpt) Base {
|
||||||
|
return NewBase(StatusInternal, msgID, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Timeout initializes a new [Base] error with reason StatusTimeout.
|
||||||
|
//
|
||||||
|
// area.timeout
|
||||||
|
func Timeout(msgID string, opts ...BaseOpt) Base {
|
||||||
|
return NewBase(StatusTimeout, msgID, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unauthorized initializes a new [Base] error with reason StatusUnauthorized
|
||||||
|
// that is used to construct [Error]. The msgID is passed to the caller
|
||||||
|
// to serve as the base for user facing error messages.
|
||||||
|
//
|
||||||
|
// msgID should be structured as component.errorBrief, for example
|
||||||
|
//
|
||||||
|
// auth.unauthorized
|
||||||
|
func Unauthorized(msgID string, opts ...BaseOpt) Base {
|
||||||
|
return NewBase(StatusUnauthorized, msgID, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Forbidden initializes a new [Base] error with reason StatusForbidden
|
||||||
|
// that is used to construct [Error]. The msgID is passed to the caller
|
||||||
|
// to serve as the base for user facing error messages.
|
||||||
|
//
|
||||||
|
// msgID should be structured as component.errorBrief, for example
|
||||||
|
//
|
||||||
|
// quota.disabled
|
||||||
|
// user.sync.forbidden
|
||||||
|
func Forbidden(msgID string, opts ...BaseOpt) Base {
|
||||||
|
return NewBase(StatusForbidden, msgID, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TooManyRequests initializes a new [Base] error with reason StatusTooManyRequests
|
||||||
|
// that is used to construct [Error]. The msgID is passed to the caller
|
||||||
|
// to serve as the base for user facing error messages.
|
||||||
|
//
|
||||||
|
// msgID should be structured as component.errorBrief, for example
|
||||||
|
//
|
||||||
|
// area.tooManyRequests
|
||||||
|
func TooManyRequests(msgID string, opts ...BaseOpt) Base {
|
||||||
|
return NewBase(StatusTooManyRequests, msgID, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotImplemented initializes a new [Base] error with reason StatusNotImplemented
|
||||||
|
// that is used to construct [Error]. The msgID is passed to the caller
|
||||||
|
// to serve as the base for user facing error messages.
|
||||||
|
//
|
||||||
|
// msgID should be structured as component.errorBrief, for example
|
||||||
|
//
|
||||||
|
// plugin.notImplemented
|
||||||
|
// auth.identity.unsupported
|
||||||
|
func NotImplemented(msgID string, opts ...BaseOpt) Base {
|
||||||
|
return NewBase(StatusNotImplemented, msgID, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
type BaseOpt func(Base) Base
|
type BaseOpt func(Base) Base
|
||||||
|
|
||||||
// WithLogLevel sets a custom log level for all errors instantiated from
|
// WithLogLevel sets a custom log level for all errors instantiated from
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ var (
|
|||||||
// same error message for the frontend statically within the
|
// same error message for the frontend statically within the
|
||||||
// package.
|
// package.
|
||||||
|
|
||||||
errAbsPath = errutil.NewBase(errutil.StatusBadRequest, "shorturl.absolutePath")
|
errAbsPath = errutil.BadRequest("shorturl.absolutePath")
|
||||||
errInvalidPath = errutil.NewBase(errutil.StatusBadRequest, "shorturl.invalidPath")
|
errInvalidPath = errutil.BadRequest("shorturl.invalidPath")
|
||||||
errUnexpected = errutil.NewBase(errutil.StatusInternal, "shorturl.unexpected")
|
errUnexpected = errutil.Internal("shorturl.unexpected")
|
||||||
)
|
)
|
||||||
|
|
||||||
func Example() {
|
func Example() {
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestBase_Is(t *testing.T) {
|
func TestBase_Is(t *testing.T) {
|
||||||
baseNotFound := NewBase(StatusNotFound, "test.notFound")
|
baseNotFound := NotFound("test.notFound")
|
||||||
baseInternal := NewBase(StatusInternal, "test.internal")
|
baseInternal := Internal("test.internal")
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
Base Base
|
Base Base
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestTemplate(t *testing.T) {
|
func TestTemplate(t *testing.T) {
|
||||||
tmpl := errutil.NewBase(errutil.StatusInternal, "template.sampleError").MustTemplate("[{{ .Public.user }}] got error: {{ .Error }}")
|
tmpl := errutil.Internal("template.sampleError").MustTemplate("[{{ .Public.user }}] got error: {{ .Error }}")
|
||||||
err := tmpl.Build(errutil.TemplateData{
|
err := tmpl.Build(errutil.TemplateData{
|
||||||
Public: map[string]interface{}{
|
Public: map[string]interface{}{
|
||||||
"user": "grot the bot",
|
"user": "grot the bot",
|
||||||
@@ -31,7 +31,7 @@ func TestTemplate(t *testing.T) {
|
|||||||
func ExampleTemplate() {
|
func ExampleTemplate() {
|
||||||
// Initialization, this is typically done on a package or global
|
// Initialization, this is typically done on a package or global
|
||||||
// level.
|
// level.
|
||||||
var tmpl = errutil.NewBase(errutil.StatusInternal, "template.sampleError").MustTemplate("[{{ .Public.user }}] got error: {{ .Error }}")
|
var tmpl = errutil.Internal("template.sampleError").MustTemplate("[{{ .Public.user }}] got error: {{ .Error }}")
|
||||||
|
|
||||||
// Construct an error based on the template.
|
// Construct an error based on the template.
|
||||||
err := tmpl.Build(errutil.TemplateData{
|
err := tmpl.Build(errutil.TemplateData{
|
||||||
@@ -50,12 +50,10 @@ func ExampleTemplate() {
|
|||||||
func ExampleTemplate_public() {
|
func ExampleTemplate_public() {
|
||||||
// Initialization, this is typically done on a package or global
|
// Initialization, this is typically done on a package or global
|
||||||
// level.
|
// level.
|
||||||
var tmpl = errutil.
|
var tmpl = errutil.Internal("template.sampleError").MustTemplate(
|
||||||
NewBase(errutil.StatusInternal, "template.sampleError").
|
"[{{ .Public.user }}] got error: {{ .Error }}",
|
||||||
MustTemplate(
|
errutil.WithPublic("Oh, no, error for {{ .Public.user }}"),
|
||||||
"[{{ .Public.user }}] got error: {{ .Error }}",
|
)
|
||||||
errutil.WithPublic("Oh, no, error for {{ .Public.user }}"),
|
|
||||||
)
|
|
||||||
|
|
||||||
// Construct an error based on the template.
|
// Construct an error based on the template.
|
||||||
//nolint:errorlint
|
//nolint:errorlint
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ type Context struct {
|
|||||||
template *template.Template
|
template *template.Template
|
||||||
}
|
}
|
||||||
|
|
||||||
var errMissingWrite = errutil.NewBase(errutil.StatusInternal, "web.missingWrite")
|
var errMissingWrite = errutil.Internal("web.missingWrite")
|
||||||
|
|
||||||
func (ctx *Context) run() {
|
func (ctx *Context) run() {
|
||||||
h := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
|
h := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
|
||||||
|
|||||||
Reference in New Issue
Block a user