export repoExists error from repository (#1335)
## Description Intercept the lower-level RepoAlreadyExists error, and field a repository package version of the same error for sdk consumers to identify when initializing corso repos. ## Type of change - [x] 🌻 Feature ## Issue(s) * #1136 ## Test Plan - [x] 💪 Manual - [x] 💚 E2E
This commit is contained in:
parent
8ddbc16077
commit
8559c0530b
@ -9,7 +9,6 @@ import (
|
|||||||
"github.com/alcionai/corso/src/cli/options"
|
"github.com/alcionai/corso/src/cli/options"
|
||||||
. "github.com/alcionai/corso/src/cli/print"
|
. "github.com/alcionai/corso/src/cli/print"
|
||||||
"github.com/alcionai/corso/src/cli/utils"
|
"github.com/alcionai/corso/src/cli/utils"
|
||||||
"github.com/alcionai/corso/src/internal/kopia"
|
|
||||||
"github.com/alcionai/corso/src/pkg/account"
|
"github.com/alcionai/corso/src/pkg/account"
|
||||||
"github.com/alcionai/corso/src/pkg/repository"
|
"github.com/alcionai/corso/src/pkg/repository"
|
||||||
"github.com/alcionai/corso/src/pkg/storage"
|
"github.com/alcionai/corso/src/pkg/storage"
|
||||||
@ -121,7 +120,7 @@ func initS3Cmd(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
r, err := repository.Initialize(ctx, a, s, options.Control())
|
r, err := repository.Initialize(ctx, a, s, options.Control())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if succeedIfExists && kopia.IsRepoAlreadyExistsError(err) {
|
if succeedIfExists && errors.Is(err, repository.ErrorRepoAlreadyExists) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -76,6 +76,11 @@ func (suite *S3IntegrationSuite) TestInitS3Cmd() {
|
|||||||
|
|
||||||
// run the command
|
// run the command
|
||||||
require.NoError(t, cmd.ExecuteContext(ctx))
|
require.NoError(t, cmd.ExecuteContext(ctx))
|
||||||
|
|
||||||
|
// a second initialization should result in an error
|
||||||
|
err = cmd.ExecuteContext(ctx)
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.ErrorIs(t, err, repository.ErrorRepoAlreadyExists)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package repository
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@ -20,6 +21,8 @@ import (
|
|||||||
"github.com/alcionai/corso/src/pkg/store"
|
"github.com/alcionai/corso/src/pkg/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var ErrorRepoAlreadyExists = errors.New("a repository was already initialized with that configuration")
|
||||||
|
|
||||||
// BackupGetter deals with retrieving metadata about backups from the
|
// BackupGetter deals with retrieving metadata about backups from the
|
||||||
// repository.
|
// repository.
|
||||||
type BackupGetter interface {
|
type BackupGetter interface {
|
||||||
@ -78,6 +81,11 @@ func Initialize(
|
|||||||
) (Repository, error) {
|
) (Repository, error) {
|
||||||
kopiaRef := kopia.NewConn(s)
|
kopiaRef := kopia.NewConn(s)
|
||||||
if err := kopiaRef.Initialize(ctx); err != nil {
|
if err := kopiaRef.Initialize(ctx); err != nil {
|
||||||
|
// replace common internal errors so that sdk users can check results with errors.Is()
|
||||||
|
if kopia.IsRepoAlreadyExistsError(err) {
|
||||||
|
return nil, ErrorRepoAlreadyExists
|
||||||
|
}
|
||||||
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// kopiaRef comes with a count of 1 and NewWrapper/NewModelStore bumps it again so safe
|
// kopiaRef comes with a count of 1 and NewWrapper/NewModelStore bumps it again so safe
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user