From 01450cde44a4c8e8c98ea5090a0cdff3a3c2081d Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Tue, 9 Jul 2024 22:18:04 +0300 Subject: [PATCH] normalized internal errors formatting --- apis/file.go | 2 +- apis/realtime.go | 2 +- models/settings/settings.go | 2 +- tokens/record.go | 8 ++++---- tools/mailer/sendmail.go | 2 +- tools/search/simple_field_resolver.go | 2 +- tools/security/jwt.go | 2 +- tools/types/json_array.go | 2 +- tools/types/json_map.go | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/apis/file.go b/apis/file.go index 05a50426..610fa25b 100644 --- a/apis/file.go +++ b/apis/file.go @@ -111,7 +111,7 @@ func (api *fileApi) download(c echo.Context) error { options, ok := fileField.Options.(*schema.FileOptions) if !ok { - return NewBadRequestError("", errors.New("Failed to load file options.")) + return NewBadRequestError("", errors.New("failed to load file options")) } // check whether the request is authorized to view the protected file diff --git a/apis/realtime.go b/apis/realtime.go index 00ba81ad..426f1703 100644 --- a/apis/realtime.go +++ b/apis/realtime.go @@ -371,7 +371,7 @@ type recordData struct { func (api *realtimeApi) broadcastRecord(action string, record *models.Record, dryCache bool) error { collection := record.Collection() if collection == nil { - return errors.New("[broadcastRecord] Record collection not set.") + return errors.New("[broadcastRecord] Record collection not set") } clients := api.app.SubscriptionsBroker().Clients() diff --git a/models/settings/settings.go b/models/settings/settings.go index a9fb35f0..32f1ebeb 100644 --- a/models/settings/settings.go +++ b/models/settings/settings.go @@ -653,7 +653,7 @@ func (c AuthProviderConfig) Validate() error { // SetupProvider loads the current AuthProviderConfig into the specified provider. func (c AuthProviderConfig) SetupProvider(provider auth.Provider) error { if !c.Enabled { - return errors.New("The provider is not enabled.") + return errors.New("the provider is not enabled") } if c.ClientId != "" { diff --git a/tokens/record.go b/tokens/record.go index 028bcc8e..6bb7dbe9 100644 --- a/tokens/record.go +++ b/tokens/record.go @@ -12,7 +12,7 @@ import ( // NewRecordAuthToken generates and returns a new auth record authentication token. func NewRecordAuthToken(app core.App, record *models.Record) (string, error) { if !record.Collection().IsAuth() { - return "", errors.New("The record is not from an auth collection.") + return "", errors.New("the record is not from an auth collection") } return security.NewJWT( @@ -29,7 +29,7 @@ func NewRecordAuthToken(app core.App, record *models.Record) (string, error) { // NewRecordVerifyToken generates and returns a new record verification token. func NewRecordVerifyToken(app core.App, record *models.Record) (string, error) { if !record.Collection().IsAuth() { - return "", errors.New("The record is not from an auth collection.") + return "", errors.New("the record is not from an auth collection") } return security.NewJWT( @@ -47,7 +47,7 @@ func NewRecordVerifyToken(app core.App, record *models.Record) (string, error) { // NewRecordResetPasswordToken generates and returns a new auth record password reset request token. func NewRecordResetPasswordToken(app core.App, record *models.Record) (string, error) { if !record.Collection().IsAuth() { - return "", errors.New("The record is not from an auth collection.") + return "", errors.New("the record is not from an auth collection") } return security.NewJWT( @@ -80,7 +80,7 @@ func NewRecordChangeEmailToken(app core.App, record *models.Record, newEmail str // NewRecordFileToken generates and returns a new record private file access token. func NewRecordFileToken(app core.App, record *models.Record) (string, error) { if !record.Collection().IsAuth() { - return "", errors.New("The record is not from an auth collection.") + return "", errors.New("the record is not from an auth collection") } return security.NewJWT( diff --git a/tools/mailer/sendmail.go b/tools/mailer/sendmail.go index 6a40523c..6826a036 100644 --- a/tools/mailer/sendmail.go +++ b/tools/mailer/sendmail.go @@ -74,5 +74,5 @@ func findSendmailPath() (string, error) { } } - return "", errors.New("Failed to locate a sendmail executable path.") + return "", errors.New("failed to locate a sendmail executable path") } diff --git a/tools/search/simple_field_resolver.go b/tools/search/simple_field_resolver.go index 09a1a651..bfd96ada 100644 --- a/tools/search/simple_field_resolver.go +++ b/tools/search/simple_field_resolver.go @@ -76,7 +76,7 @@ func (r *SimpleFieldResolver) UpdateQuery(query *dbx.SelectQuery) error { // Returns error if `field` is not in `r.allowedFields`. func (r *SimpleFieldResolver) Resolve(field string) (*ResolverResult, error) { if !list.ExistInSliceWithRegex(field, r.allowedFields) { - return nil, fmt.Errorf("Failed to resolve field %q.", field) + return nil, fmt.Errorf("failed to resolve field %q", field) } parts := strings.Split(field, ".") diff --git a/tools/security/jwt.go b/tools/security/jwt.go index 83c818db..78faf7d9 100644 --- a/tools/security/jwt.go +++ b/tools/security/jwt.go @@ -39,7 +39,7 @@ func ParseJWT(token string, verificationKey string) (jwt.MapClaims, error) { return claims, nil } - return nil, errors.New("Unable to parse token.") + return nil, errors.New("unable to parse token") } // NewJWT generates and returns new HS256 signed JWT. diff --git a/tools/types/json_array.go b/tools/types/json_array.go index 3a8f8b38..b06f116e 100644 --- a/tools/types/json_array.go +++ b/tools/types/json_array.go @@ -41,7 +41,7 @@ func (m *JsonArray[T]) Scan(value any) error { case string: data = []byte(v) default: - return fmt.Errorf("Failed to unmarshal JsonArray value: %q.", value) + return fmt.Errorf("failed to unmarshal JsonArray value: %q", value) } if len(data) == 0 { diff --git a/tools/types/json_map.go b/tools/types/json_map.go index bb2b14ec..a94ad229 100644 --- a/tools/types/json_map.go +++ b/tools/types/json_map.go @@ -56,7 +56,7 @@ func (m *JsonMap) Scan(value any) error { case string: data = []byte(v) default: - return fmt.Errorf("Failed to unmarshal JsonMap value: %q.", value) + return fmt.Errorf("failed to unmarshal JsonMap value: %q", value) } if len(data) == 0 {