Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

EVEREST-301 Shorten the error message for backup storage creation #215

Merged
merged 9 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion api-tests/tests/backup-storages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ test('create backup storage failures', async ({ request }) => {
accessKey: 'ssdssd',
secretKey: 'ssdssdssdssd',
},
errorText: 'Could not connect to the backup storage, please check the new credentials are correct',
errorText: `Creating storage is not implemented for 'azure'`,
},
]

Expand Down
8 changes: 3 additions & 5 deletions api/backup_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,11 @@
if errors.Is(err, gorm.ErrRecordNotFound) {
return ctx.JSON(http.StatusNotFound, Error{Message: pointer.ToString("Could not find backup storage")})
}
if errors.Is(err, errUserFacingMsg) {
return ctx.JSON(http.StatusBadRequest, Error{
Message: pointer.ToString(fmt.Sprintf("Could not connect to the backup storage, please check the new credentials are correct: %s", err)),
})
}
return ctx.JSON(http.StatusBadRequest, Error{

Check failure on line 252 in api/backup_storage.go

View workflow job for this annotation

GitHub Actions / Check (1.21.x, false)

unreachable-code: unreachable code after this statement (revive)
gen1us2k marked this conversation as resolved.
Show resolved Hide resolved
Message: pointer.ToString(fmt.Sprintf("Could not connect to the backup storage, please check the new credentials are correct: %s", err)),
})

e.l.Error(err)

Check failure on line 256 in api/backup_storage.go

View workflow job for this annotation

GitHub Actions / Check (1.21.x, false)

unreachable: unreachable code (govet)
gen1us2k marked this conversation as resolved.
Show resolved Hide resolved
return ctx.JSON(http.StatusBadRequest, Error{
Message: pointer.ToString("Could not connect to the backup storage, please check the new credentials are correct"),
})
Expand Down
4 changes: 0 additions & 4 deletions api/everest.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ type EverestServer struct {
echo *echo.Echo
}

// errUserFacingMsg represents an error with a message which can be returned
// back to the user directly without any modification.
var errUserFacingMsg = errors.New("")

// NewEverestServer creates and configures everest API.
func NewEverestServer(c *config.EverestConfig, l *zap.SugaredLogger) (*EverestServer, error) {
e := &EverestServer{
Expand Down
17 changes: 7 additions & 10 deletions api/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ func s3Access(l *zap.SugaredLogger, endpoint *string, accessKey, secretKey, buck
Credentials: credentials.NewStaticCredentials(accessKey, secretKey, ""),
})
if err != nil {
return err
l.Error(err)
return errors.New("could not initialize S3 session")
}

// Create a new S3 client with the session
Expand All @@ -196,7 +197,7 @@ func s3Access(l *zap.SugaredLogger, endpoint *string, accessKey, secretKey, buck
})
if err != nil {
l.Error(err)
return errors.Join(errUserFacingMsg, errors.New("could not issue head request to S3 bucket"))
return errors.New("could not issue head request to S3 bucket")
}

testKey := "everest-write-test"
Expand All @@ -207,7 +208,7 @@ func s3Access(l *zap.SugaredLogger, endpoint *string, accessKey, secretKey, buck
})
if err != nil {
l.Error(err)
return errors.Join(errUserFacingMsg, errors.New("could not write to S3 bucket"))
return errors.New("could not write to S3 bucket")
}

_, err = svc.GetObject(&s3.GetObjectInput{
Expand All @@ -216,7 +217,7 @@ func s3Access(l *zap.SugaredLogger, endpoint *string, accessKey, secretKey, buck
})
if err != nil {
l.Error(err)
return errors.Join(errUserFacingMsg, errors.New("could not read from S3 bucket"))
return errors.New("could not read from S3 bucket")
}

_, err = svc.DeleteObject(&s3.DeleteObjectInput{
Expand All @@ -225,7 +226,7 @@ func s3Access(l *zap.SugaredLogger, endpoint *string, accessKey, secretKey, buck
})
if err != nil {
l.Error(err)
return errors.Join(errUserFacingMsg, errors.New("could not delete an object from S3 bucket"))
return errors.New("could not delete an object from S3 bucket")
}

return nil
Expand Down Expand Up @@ -266,12 +267,8 @@ func validateCreateBackupStorageRequest(ctx echo.Context, l *zap.SugaredLogger)

// check data access
if err := validateStorageAccessByCreate(params, l); err != nil {
if errors.Is(err, errUserFacingMsg) {
gen1us2k marked this conversation as resolved.
Show resolved Hide resolved
return nil, errors.Join(err, errors.New("could not connect to the backup storage, please check the new credentials are correct"))
}

l.Error(err)
return nil, errors.New("could not connect to the backup storage, please check the new credentials are correct")
return nil, err
This conversation was marked as resolved.
Show resolved Hide resolved
}

return &params, nil
Expand Down
Loading