From 9d73d0c8e2ceaf47eaa0f460560f7080a9f1ccce Mon Sep 17 00:00:00 2001 From: Keepers Date: Mon, 27 Mar 2023 22:01:54 -0600 Subject: [PATCH] replace errors.* with clues.* (#2924) Mostly find/replace on errors.N and errors.W. Also turns all wrapf into wrap, and removes as many errorf calls as possible. Might follow up with a linter to enforce this change. --- #### Does this PR need a docs update or release note? - [x] :no_entry: No #### Type of change - [x] :broom: Tech Debt/Cleanup #### Issue(s) * #1970 #### Test Plan - [x] :zap: Unit test - [x] :green_heart: E2E --- src/cli/backup/backup.go | 19 ++-- src/cli/backup/exchange.go | 12 +-- src/cli/backup/exchange_e2e_test.go | 2 +- src/cli/backup/exchange_test.go | 2 +- src/cli/backup/onedrive.go | 10 +- src/cli/backup/onedrive_e2e_test.go | 2 +- src/cli/backup/onedrive_test.go | 2 +- src/cli/backup/sharepoint.go | 14 +-- src/cli/backup/sharepoint_e2e_test.go | 2 +- src/cli/backup/sharepoint_test.go | 2 +- src/cli/config/account.go | 12 +-- src/cli/config/config.go | 12 +-- src/cli/config/config_test.go | 2 +- src/cli/config/storage.go | 14 +-- src/cli/print/print_test.go | 2 +- src/cli/repo/s3.go | 21 ++-- src/cli/repo/s3_e2e_test.go | 2 +- src/cli/restore/exchange.go | 9 +- src/cli/restore/exchange_e2e_test.go | 2 +- src/cli/restore/onedrive.go | 9 +- src/cli/restore/sharepoint.go | 9 +- src/cli/utils/exchange.go | 16 ++-- src/cli/utils/exchange_test.go | 2 +- src/cli/utils/onedrive.go | 14 +-- src/cli/utils/sharepoint.go | 14 +-- src/cli/utils/testdata/opts.go | 13 +-- src/cli/utils/utils.go | 4 +- src/cli/utils/utils_test.go | 2 +- src/cmd/factory/impl/common.go | 11 +-- src/cmd/getM365/getItem.go | 14 +-- src/cmd/mdgen/mdgen.go | 13 +-- src/cmd/purge/purge.go | 20 ++-- src/internal/common/configs_test.go | 2 +- src/internal/common/crash/crash_test.go | 5 +- src/internal/common/time.go | 13 ++- src/internal/common/time_test.go | 2 +- src/internal/connector/data_collections.go | 5 +- .../connector/data_collections_test.go | 2 +- src/internal/connector/discovery/api/api.go | 4 +- .../connector/discovery/api/beta_service.go | 6 +- .../discovery/api/beta_service_test.go | 2 +- src/internal/connector/discovery/api/users.go | 4 +- .../connector/discovery/api/users_test.go | 2 +- src/internal/connector/discovery/discovery.go | 5 +- .../connector/discovery/discovery_test.go | 2 +- src/internal/connector/exchange/api/api.go | 7 +- .../connector/exchange/api/api_test.go | 2 +- .../connector/exchange/api/events_test.go | 2 +- src/internal/connector/exchange/attachment.go | 2 +- .../connector/exchange/cache_container.go | 5 +- .../exchange/contact_folder_cache.go | 7 +- .../connector/exchange/container_resolver.go | 9 +- .../exchange/container_resolver_test.go | 2 +- .../connector/exchange/data_collections.go | 5 +- .../exchange/data_collections_test.go | 2 +- .../exchange/event_calendar_cache.go | 11 +-- .../exchange/exchange_data_collection_test.go | 2 +- .../exchange/folder_resolver_test.go | 2 +- .../connector/exchange/iterators_test.go | 2 +- .../connector/exchange/mail_folder_cache.go | 7 +- .../exchange/mail_folder_cache_test.go | 2 +- .../connector/exchange/restore_test.go | 2 +- .../connector/exchange/service_functions.go | 5 +- .../connector/exchange/service_iterators.go | 3 +- .../exchange/service_iterators_test.go | 5 +- .../connector/exchange/service_restore.go | 15 ++- .../connector/graph/cache_container.go | 3 +- src/internal/connector/graph/errors.go | 2 +- src/internal/connector/graph/errors_test.go | 2 +- .../connector/graph/metadata/metadata_test.go | 2 +- .../connector/graph/metadata_collection.go | 10 +- .../graph/metadata_collection_test.go | 2 +- src/internal/connector/graph/service.go | 11 +-- src/internal/connector/graph/service_test.go | 2 +- src/internal/connector/graph_connector.go | 4 +- .../graph_connector_disconnected_test.go | 2 +- .../connector/graph_connector_helper_test.go | 2 +- .../graph_connector_onedrive_test.go | 2 +- .../connector/graph_connector_test.go | 2 +- .../mock_data_collection_test.go | 2 +- .../connector/mockconnector/mock_data_list.go | 2 +- .../mockconnector/mock_data_message.go | 7 +- .../connector/onedrive/api/drive_test.go | 2 +- src/internal/connector/onedrive/collection.go | 3 +- .../connector/onedrive/collection_test.go | 2 +- .../connector/onedrive/collections.go | 4 +- .../connector/onedrive/collections_test.go | 2 +- .../connector/onedrive/data_collections.go | 3 +- src/internal/connector/onedrive/drive.go | 5 +- src/internal/connector/onedrive/item.go | 5 +- src/internal/connector/onedrive/item_test.go | 2 +- src/internal/connector/onedrive/permission.go | 5 +- .../connector/onedrive/restore_test.go | 7 +- .../connector/onedrive/service_test.go | 2 +- .../connector/sharepoint/api/helper_test.go | 2 +- .../connector/sharepoint/api/pages.go | 9 +- .../connector/sharepoint/api/pages_test.go | 2 +- .../connector/sharepoint/collection_test.go | 2 +- .../connector/sharepoint/data_collections.go | 5 +- .../sharepoint/data_collections_test.go | 2 +- .../connector/sharepoint/helper_test.go | 2 +- .../connector/sharepoint/list_test.go | 2 +- src/internal/connector/support/m365Support.go | 16 ++-- .../connector/support/m365Support_test.go | 2 +- .../connector/support/m365Transform_test.go | 2 +- .../uploadsession/uploadsession_test.go | 2 +- src/internal/data/data_collection.go | 5 +- src/internal/data/data_collection_test.go | 2 +- src/internal/diagnostics/diagnostics.go | 4 +- src/internal/events/events_test.go | 2 +- src/internal/events/mock/mock.go | 4 +- src/internal/kopia/conn.go | 8 +- src/internal/kopia/conn_test.go | 2 +- src/internal/kopia/data_collection_test.go | 7 +- src/internal/kopia/model_store.go | 20 ++-- src/internal/kopia/model_store_test.go | 2 +- src/internal/kopia/path_encoder_test.go | 2 +- src/internal/kopia/snapshot_manager.go | 5 +- src/internal/kopia/upload.go | 96 +++++++++---------- src/internal/kopia/upload_test.go | 4 +- src/internal/kopia/wrapper.go | 9 +- src/internal/kopia/wrapper_test.go | 2 +- src/internal/observe/observe_test.go | 2 +- src/internal/operations/backup.go | 27 +++--- .../operations/backup_integration_test.go | 5 +- src/internal/operations/backup_test.go | 28 +++--- src/internal/operations/common.go | 5 +- src/internal/operations/manifests.go | 4 +- src/internal/operations/manifests_test.go | 2 +- src/internal/operations/operation.go | 6 +- src/internal/operations/operation_test.go | 2 +- src/internal/operations/restore.go | 17 ++-- src/internal/operations/restore_test.go | 2 +- src/internal/streamstore/mock/mock.go | 14 ++- src/internal/streamstore/streamstore.go | 7 +- src/internal/tester/account.go | 2 +- src/internal/tester/config.go | 7 +- src/internal/tester/storage.go | 2 +- src/pkg/account/account.go | 4 +- src/pkg/account/m365.go | 3 +- src/pkg/account/m365_test.go | 2 +- src/pkg/backup/details/details_test.go | 2 +- src/pkg/credentials/aws.go | 3 +- src/pkg/credentials/corso.go | 3 +- src/pkg/credentials/credentials.go | 4 +- src/pkg/credentials/m365.go | 3 +- src/pkg/fault/example_fault_test.go | 24 ++--- src/pkg/fault/fault_test.go | 17 ++-- src/pkg/fault/item_test.go | 8 +- src/pkg/fault/testdata/testdata.go | 2 +- src/pkg/path/onedrive_test.go | 2 +- src/pkg/path/path.go | 17 ++-- src/pkg/path/path_test.go | 2 +- src/pkg/path/resource_path.go | 7 +- src/pkg/path/resource_path_test.go | 2 +- src/pkg/path/service_category_test.go | 2 +- .../loadtest/repository_load_test.go | 2 +- src/pkg/repository/repository.go | 12 +-- src/pkg/repository/repository_test.go | 2 +- .../repository/repository_unexported_test.go | 2 +- src/pkg/selectors/exchange_test.go | 2 +- src/pkg/selectors/helpers_test.go | 2 +- src/pkg/selectors/onedrive_test.go | 2 +- src/pkg/selectors/scopes_test.go | 2 +- src/pkg/selectors/selectors.go | 8 +- src/pkg/selectors/selectors_test.go | 2 +- src/pkg/selectors/sharepoint_test.go | 2 +- src/pkg/services/m365/m365.go | 9 +- src/pkg/services/m365/m365_test.go | 2 +- src/pkg/storage/common.go | 3 +- src/pkg/storage/common_test.go | 2 +- src/pkg/storage/s3.go | 3 +- src/pkg/storage/storage.go | 5 +- src/pkg/store/backup.go | 4 +- src/pkg/store/backup_test.go | 2 +- src/pkg/store/mock/store_mock.go | 12 +-- 176 files changed, 525 insertions(+), 552 deletions(-) diff --git a/src/cli/backup/backup.go b/src/cli/backup/backup.go index 65e8a69a9..a6e8c3af8 100644 --- a/src/cli/backup/backup.go +++ b/src/cli/backup/backup.go @@ -6,6 +6,9 @@ import ( "strings" "github.com/alcionai/clues" + "github.com/pkg/errors" + "github.com/spf13/cobra" + "github.com/alcionai/corso/src/cli/config" "github.com/alcionai/corso/src/cli/options" . "github.com/alcionai/corso/src/cli/print" @@ -19,8 +22,6 @@ import ( "github.com/alcionai/corso/src/pkg/repository" "github.com/alcionai/corso/src/pkg/selectors" "github.com/alcionai/corso/src/pkg/store" - "github.com/pkg/errors" - "github.com/spf13/cobra" ) // --------------------------------------------------------------------------- @@ -235,7 +236,7 @@ func runBackups( bups, berrs := r.Backups(ctx, bIDs) if berrs.Failure() != nil { - return Only(ctx, errors.Wrap(berrs.Failure(), "Unable to retrieve backup results from storage")) + return Only(ctx, clues.Wrap(berrs.Failure(), "Unable to retrieve backup results from storage")) } Info(ctx, "Completed Backups:") @@ -258,7 +259,7 @@ func runBackups( // genericDeleteCommand is a helper function that all services can use // for the removal of an entry from the repository func genericDeleteCommand(cmd *cobra.Command, bID, designation string, args []string) error { - ctx := cmd.Context() + ctx := clues.Add(cmd.Context(), "delete_backup_id", bID) if utils.HasNoFlagsAndShownHelp(cmd) { return nil @@ -272,7 +273,7 @@ func genericDeleteCommand(cmd *cobra.Command, bID, designation string, args []st defer utils.CloseRepo(ctx, r) if err := r.DeleteBackup(ctx, model.StableID(bID)); err != nil { - return Only(ctx, errors.Wrapf(err, "Deleting backup %s", bID)) + return Only(ctx, clues.Wrap(err, "Deleting backup "+bID)) } Infof(ctx, "Deleted %s backup %s", designation, bID) @@ -296,10 +297,10 @@ func genericListCommand(cmd *cobra.Command, bID string, service path.ServiceType fe, b, errs := r.GetBackupErrors(ctx, bID) if errs.Failure() != nil { if errors.Is(errs.Failure(), data.ErrNotFound) { - return Only(ctx, errors.Errorf("No backup exists with the id %s", bID)) + return Only(ctx, clues.New("No backup exists with the id "+bID)) } - return Only(ctx, errors.Wrap(err, "Failed to find backup "+bID)) + return Only(ctx, clues.Wrap(err, "Failed to find backup "+bID)) } b.Print(ctx) @@ -310,7 +311,7 @@ func genericListCommand(cmd *cobra.Command, bID string, service path.ServiceType bs, err := r.BackupsByTag(ctx, store.Service(service)) if err != nil { - return Only(ctx, errors.Wrap(err, "Failed to list backups in the repository")) + return Only(ctx, clues.Wrap(err, "Failed to list backups in the repository")) } backup.PrintAll(ctx, bs) @@ -326,7 +327,7 @@ func getAccountAndConnect(ctx context.Context) (repository.Repository, *account. r, err := repository.Connect(ctx, cfg.Account, cfg.Storage, options.Control()) if err != nil { - return nil, nil, errors.Wrapf(err, "Failed to connect to the %s repository", cfg.Storage.Provider) + return nil, nil, clues.Wrap(err, "Failed to connect to the "+cfg.Storage.Provider.String()+" repository") } return r, &cfg.Account, nil diff --git a/src/cli/backup/exchange.go b/src/cli/backup/exchange.go index 87a1f2c56..58fad9e29 100644 --- a/src/cli/backup/exchange.go +++ b/src/cli/backup/exchange.go @@ -3,11 +3,11 @@ package backup import ( "context" + "github.com/alcionai/clues" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/pflag" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/cli/options" . "github.com/alcionai/corso/src/cli/print" "github.com/alcionai/corso/src/cli/utils" @@ -171,7 +171,7 @@ func createExchangeCmd(cmd *cobra.Command, args []string) error { users, err := m365.UserPNs(ctx, *acct, errs) if err != nil { - return Only(ctx, errors.Wrap(err, "Failed to retrieve M365 user(s)")) + return Only(ctx, clues.Wrap(err, "Failed to retrieve M365 user(s)")) } selectorSet := []selectors.Selector{} @@ -213,12 +213,12 @@ func exchangeBackupCreateSelectors(userIDs, cats []string) *selectors.ExchangeBa func validateExchangeBackupCreateFlags(userIDs, cats []string) error { if len(userIDs) == 0 { - return errors.New("--user requires one or more email addresses or the wildcard '*'") + return clues.New("--user requires one or more email addresses or the wildcard '*'") } for _, d := range cats { if d != dataContacts && d != dataEmail && d != dataEvents { - return errors.New( + return clues.New( d + " is an unrecognized data type; must be one of " + dataContacts + ", " + dataEmail + ", or " + dataEvents) } } @@ -336,10 +336,10 @@ func runDetailsExchangeCmd( // TODO: log/track recoverable errors if errs.Failure() != nil { if errors.Is(errs.Failure(), data.ErrNotFound) { - return nil, errors.Errorf("No backup exists with the id %s", backupID) + return nil, clues.New("No backup exists with the id " + backupID) } - return nil, errors.Wrap(errs.Failure(), "Failed to get backup details in the repository") + return nil, clues.Wrap(errs.Failure(), "Failed to get backup details in the repository") } ctx = clues.Add(ctx, "details_entries", len(d.Entries)) diff --git a/src/cli/backup/exchange_e2e_test.go b/src/cli/backup/exchange_e2e_test.go index d8bcb7fdf..5dc70e357 100644 --- a/src/cli/backup/exchange_e2e_test.go +++ b/src/cli/backup/exchange_e2e_test.go @@ -5,13 +5,13 @@ import ( "strings" "testing" + "github.com/alcionai/clues" "github.com/google/uuid" "github.com/spf13/viper" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/cli" "github.com/alcionai/corso/src/cli/config" "github.com/alcionai/corso/src/cli/print" diff --git a/src/cli/backup/exchange_test.go b/src/cli/backup/exchange_test.go index d48f8255f..661301ca4 100644 --- a/src/cli/backup/exchange_test.go +++ b/src/cli/backup/exchange_test.go @@ -3,12 +3,12 @@ package backup import ( "testing" + "github.com/alcionai/clues" "github.com/spf13/cobra" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/cli/utils" "github.com/alcionai/corso/src/cli/utils/testdata" "github.com/alcionai/corso/src/internal/tester" diff --git a/src/cli/backup/onedrive.go b/src/cli/backup/onedrive.go index 0210760fa..642c990ca 100644 --- a/src/cli/backup/onedrive.go +++ b/src/cli/backup/onedrive.go @@ -3,11 +3,11 @@ package backup import ( "context" + "github.com/alcionai/clues" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/pflag" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/cli/options" . "github.com/alcionai/corso/src/cli/print" "github.com/alcionai/corso/src/cli/utils" @@ -146,7 +146,7 @@ func createOneDriveCmd(cmd *cobra.Command, args []string) error { users, err := m365.UserPNs(ctx, *acct, errs) if err != nil { - return Only(ctx, errors.Wrap(err, "Failed to retrieve M365 users")) + return Only(ctx, clues.Wrap(err, "Failed to retrieve M365 users")) } selectorSet := []selectors.Selector{} @@ -165,7 +165,7 @@ func createOneDriveCmd(cmd *cobra.Command, args []string) error { func validateOneDriveBackupCreateFlags(users []string) error { if len(users) == 0 { - return errors.New("requires one or more --user ids or the wildcard --user *") + return clues.New("requires one or more --user ids or the wildcard --user *") } return nil @@ -275,10 +275,10 @@ func runDetailsOneDriveCmd( // TODO: log/track recoverable errors if errs.Failure() != nil { if errors.Is(errs.Failure(), data.ErrNotFound) { - return nil, errors.Errorf("no backup exists with the id %s", backupID) + return nil, clues.New("no backup exists with the id " + backupID) } - return nil, errors.Wrap(errs.Failure(), "Failed to get backup details in the repository") + return nil, clues.Wrap(errs.Failure(), "Failed to get backup details in the repository") } ctx = clues.Add(ctx, "details_entries", len(d.Entries)) diff --git a/src/cli/backup/onedrive_e2e_test.go b/src/cli/backup/onedrive_e2e_test.go index d1f2fbf7f..515002f31 100644 --- a/src/cli/backup/onedrive_e2e_test.go +++ b/src/cli/backup/onedrive_e2e_test.go @@ -5,13 +5,13 @@ import ( "strings" "testing" + "github.com/alcionai/clues" "github.com/google/uuid" "github.com/spf13/viper" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/cli" "github.com/alcionai/corso/src/cli/config" "github.com/alcionai/corso/src/cli/print" diff --git a/src/cli/backup/onedrive_test.go b/src/cli/backup/onedrive_test.go index 9cbb4a95b..00d8576f7 100644 --- a/src/cli/backup/onedrive_test.go +++ b/src/cli/backup/onedrive_test.go @@ -3,12 +3,12 @@ package backup import ( "testing" + "github.com/alcionai/clues" "github.com/spf13/cobra" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/cli/utils/testdata" "github.com/alcionai/corso/src/internal/tester" ) diff --git a/src/cli/backup/sharepoint.go b/src/cli/backup/sharepoint.go index 07cc79b7d..59f1c8e0b 100644 --- a/src/cli/backup/sharepoint.go +++ b/src/cli/backup/sharepoint.go @@ -3,11 +3,11 @@ package backup import ( "context" + "github.com/alcionai/clues" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/pflag" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/cli/options" . "github.com/alcionai/corso/src/cli/print" "github.com/alcionai/corso/src/cli/utils" @@ -161,12 +161,12 @@ func createSharePointCmd(cmd *cobra.Command, args []string) error { gc, err := connector.NewGraphConnector(ctx, graph.HTTPClient(graph.NoTimeout()), *acct, connector.Sites, errs) if err != nil { - return Only(ctx, errors.Wrap(err, "Failed to connect to Microsoft APIs")) + return Only(ctx, clues.Wrap(err, "Failed to connect to Microsoft APIs")) } sel, err := sharePointBackupCreateSelectors(ctx, utils.SiteID, utils.WebURL, sharepointData, gc) if err != nil { - return Only(ctx, errors.Wrap(err, "Retrieving up sharepoint sites by ID and URL")) + return Only(ctx, clues.Wrap(err, "Retrieving up sharepoint sites by ID and URL")) } selectorSet := []selectors.Selector{} @@ -185,7 +185,7 @@ func createSharePointCmd(cmd *cobra.Command, args []string) error { func validateSharePointBackupCreateFlags(sites, weburls, cats []string) error { if len(sites) == 0 && len(weburls) == 0 { - return errors.New( + return clues.New( "requires one or more --" + utils.SiteFN + " urls, or the wildcard --" + utils.SiteFN + " *", @@ -194,7 +194,7 @@ func validateSharePointBackupCreateFlags(sites, weburls, cats []string) error { for _, d := range cats { if d != dataLibraries && d != dataPages { - return errors.New( + return clues.New( d + " is an unrecognized data type; either " + dataLibraries + "or " + dataPages, ) } @@ -383,10 +383,10 @@ func runDetailsSharePointCmd( // TODO: log/track recoverable errors if errs.Failure() != nil { if errors.Is(errs.Failure(), data.ErrNotFound) { - return nil, errors.Errorf("no backup exists with the id %s", backupID) + return nil, clues.New("no backup exists with the id " + backupID) } - return nil, errors.Wrap(errs.Failure(), "Failed to get backup details in the repository") + return nil, clues.Wrap(errs.Failure(), "Failed to get backup details in the repository") } ctx = clues.Add(ctx, "details_entries", len(d.Entries)) diff --git a/src/cli/backup/sharepoint_e2e_test.go b/src/cli/backup/sharepoint_e2e_test.go index bb6f951dd..94289a7d5 100644 --- a/src/cli/backup/sharepoint_e2e_test.go +++ b/src/cli/backup/sharepoint_e2e_test.go @@ -5,13 +5,13 @@ import ( "strings" "testing" + "github.com/alcionai/clues" "github.com/google/uuid" "github.com/spf13/viper" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/cli" "github.com/alcionai/corso/src/cli/config" "github.com/alcionai/corso/src/cli/print" diff --git a/src/cli/backup/sharepoint_test.go b/src/cli/backup/sharepoint_test.go index e7ed3df9e..917977cd5 100644 --- a/src/cli/backup/sharepoint_test.go +++ b/src/cli/backup/sharepoint_test.go @@ -3,12 +3,12 @@ package backup import ( "testing" + "github.com/alcionai/clues" "github.com/spf13/cobra" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/cli/utils" "github.com/alcionai/corso/src/cli/utils/testdata" "github.com/alcionai/corso/src/internal/connector" diff --git a/src/cli/config/account.go b/src/cli/config/account.go index b78954ee9..3bcd9fcd2 100644 --- a/src/cli/config/account.go +++ b/src/cli/config/account.go @@ -3,7 +3,7 @@ package config import ( "os" - "github.com/pkg/errors" + "github.com/alcionai/clues" "github.com/spf13/viper" "github.com/alcionai/corso/src/cli/utils" @@ -18,7 +18,7 @@ func m365ConfigsFromViper(vpr *viper.Viper) (account.M365Config, error) { providerType := vpr.GetString(AccountProviderTypeKey) if providerType != account.ProviderM365.String() { - return m365, errors.New("unsupported account provider: " + providerType) + return m365, clues.New("unsupported account provider: " + providerType) } m365.AzureTenantID = vpr.GetString(AzureTenantIDKey) @@ -49,18 +49,18 @@ func configureAccount( if readConfigFromViper { m365Cfg, err = m365ConfigsFromViper(vpr) if err != nil { - return acct, errors.Wrap(err, "reading m365 configs from corso config file") + return acct, clues.Wrap(err, "reading m365 configs from corso config file") } if err := mustMatchConfig(vpr, m365Overrides(overrides)); err != nil { - return acct, errors.Wrap(err, "verifying m365 configs in corso config file") + return acct, clues.Wrap(err, "verifying m365 configs in corso config file") } } // compose the m365 config and credentials m365 := credentials.GetM365() if err := m365.Validate(); err != nil { - return acct, errors.Wrap(err, "validating m365 credentials") + return acct, clues.Wrap(err, "validating m365 credentials") } m365Cfg = account.M365Config{ @@ -83,7 +83,7 @@ func configureAccount( // build the account acct, err = account.NewAccount(account.ProviderM365, m365Cfg) if err != nil { - return acct, errors.Wrap(err, "retrieving m365 account configuration") + return acct, clues.Wrap(err, "retrieving m365 account configuration") } return acct, nil diff --git a/src/cli/config/config.go b/src/cli/config/config.go index 7c05190fd..d6c9830b5 100644 --- a/src/cli/config/config.go +++ b/src/cli/config/config.go @@ -6,7 +6,7 @@ import ( "path/filepath" "strings" - "github.com/pkg/errors" + "github.com/alcionai/clues" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -127,7 +127,7 @@ func initWithViper(vpr *viper.Viper, configFP string) error { ext := filepath.Ext(configFP) if len(ext) == 0 { - return errors.New("config file requires an extension e.g. `toml`") + return clues.New("config file requires an extension e.g. `toml`") } fileName := filepath.Base(configFP) @@ -265,7 +265,7 @@ func getStorageAndAccountWithViper( err = vpr.ReadInConfig() if err != nil { if _, ok := err.(viper.ConfigFileNotFoundError); !ok { - return config, errors.Wrap(err, "reading corso config file: "+vpr.ConfigFileUsed()) + return config, clues.Wrap(err, "reading corso config file: "+vpr.ConfigFileUsed()) } readConfigFromViper = false @@ -277,12 +277,12 @@ func getStorageAndAccountWithViper( config.Account, err = configureAccount(vpr, readConfigFromViper, overrides) if err != nil { - return config, errors.Wrap(err, "retrieving account configuration details") + return config, clues.Wrap(err, "retrieving account configuration details") } config.Storage, err = configureStorage(vpr, readConfigFromViper, overrides) if err != nil { - return config, errors.Wrap(err, "retrieving storage provider details") + return config, clues.Wrap(err, "retrieving storage provider details") } return config, nil @@ -317,7 +317,7 @@ func mustMatchConfig(vpr *viper.Viper, m map[string]string) error { vv := vpr.GetString(tomlK) if v != vv { - return errors.New("value of " + k + " (" + v + ") does not match corso configuration value (" + vv + ")") + return clues.New("value of " + k + " (" + v + ") does not match corso configuration value (" + vv + ")") } } diff --git a/src/cli/config/config_test.go b/src/cli/config/config_test.go index 53f7b6e36..d9b2be563 100644 --- a/src/cli/config/config_test.go +++ b/src/cli/config/config_test.go @@ -6,12 +6,12 @@ import ( "path/filepath" "testing" + "github.com/alcionai/clues" "github.com/spf13/viper" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/credentials" diff --git a/src/cli/config/storage.go b/src/cli/config/storage.go index 5049d5a07..a10c3315e 100644 --- a/src/cli/config/storage.go +++ b/src/cli/config/storage.go @@ -5,8 +5,8 @@ import ( "path/filepath" "strconv" + "github.com/alcionai/clues" "github.com/aws/aws-sdk-go/aws/defaults" - "github.com/pkg/errors" "github.com/spf13/viper" "github.com/alcionai/corso/src/cli/utils" @@ -21,7 +21,7 @@ func s3ConfigsFromViper(vpr *viper.Viper) (storage.S3Config, error) { providerType := vpr.GetString(StorageProviderTypeKey) if providerType != storage.ProviderS3.String() { - return s3Config, errors.New("unsupported storage provider: " + providerType) + return s3Config, clues.New("unsupported storage provider: " + providerType) } s3Config.Bucket = vpr.GetString(BucketNameKey) @@ -59,7 +59,7 @@ func configureStorage( if readConfigFromViper { if s3Cfg, err = s3ConfigsFromViper(vpr); err != nil { - return store, errors.Wrap(err, "reading s3 configs from corso config file") + return store, clues.Wrap(err, "reading s3 configs from corso config file") } if b, ok := overrides[storage.Bucket]; ok { @@ -71,13 +71,13 @@ func configureStorage( } if err := mustMatchConfig(vpr, s3Overrides(overrides)); err != nil { - return store, errors.Wrap(err, "verifying s3 configs in corso config file") + return store, clues.Wrap(err, "verifying s3 configs in corso config file") } } _, err = defaults.CredChain(defaults.Config().WithCredentialsChainVerboseErrors(true), defaults.Handlers()).Get() if err != nil { - return store, errors.Wrap(err, "validating aws credentials") + return store, clues.Wrap(err, "validating aws credentials") } s3Cfg = storage.S3Config{ @@ -97,7 +97,7 @@ func configureStorage( // compose the common config and credentials corso := credentials.GetCorso() if err := corso.Validate(); err != nil { - return store, errors.Wrap(err, "validating corso credentials") + return store, clues.Wrap(err, "validating corso credentials") } cCfg := storage.CommonConfig{ @@ -122,7 +122,7 @@ func configureStorage( // build the storage store, err = storage.NewStorage(storage.ProviderS3, s3Cfg, cCfg) if err != nil { - return store, errors.Wrap(err, "configuring repository storage") + return store, clues.Wrap(err, "configuring repository storage") } return store, nil diff --git a/src/cli/print/print_test.go b/src/cli/print/print_test.go index c495c933b..7a857e23a 100644 --- a/src/cli/print/print_test.go +++ b/src/cli/print/print_test.go @@ -4,11 +4,11 @@ import ( "bytes" "testing" + "github.com/alcionai/clues" "github.com/spf13/cobra" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/tester" ) diff --git a/src/cli/repo/s3.go b/src/cli/repo/s3.go index cf3580921..8214273b5 100644 --- a/src/cli/repo/s3.go +++ b/src/cli/repo/s3.go @@ -4,6 +4,7 @@ import ( "strconv" "strings" + "github.com/alcionai/clues" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -126,19 +127,19 @@ func initS3Cmd(cmd *cobra.Command, args []string) error { s3Cfg, err := cfg.Storage.S3Config() if err != nil { - return Only(ctx, errors.Wrap(err, "Retrieving s3 configuration")) + return Only(ctx, clues.Wrap(err, "Retrieving s3 configuration")) } if strings.HasPrefix(s3Cfg.Endpoint, "http://") || strings.HasPrefix(s3Cfg.Endpoint, "https://") { invalidEndpointErr := "endpoint doesn't support specifying protocol. " + "pass --disable-tls flag to use http:// instead of default https://" - return Only(ctx, errors.New(invalidEndpointErr)) + return Only(ctx, clues.New(invalidEndpointErr)) } m365, err := cfg.Account.M365Config() if err != nil { - return Only(ctx, errors.Wrap(err, "Failed to parse m365 account config")) + return Only(ctx, clues.Wrap(err, "Failed to parse m365 account config")) } r, err := repository.Initialize(ctx, cfg.Account, cfg.Storage, options.Control()) @@ -147,7 +148,7 @@ func initS3Cmd(cmd *cobra.Command, args []string) error { return nil } - return Only(ctx, errors.Wrap(err, "Failed to initialize a new S3 repository")) + return Only(ctx, clues.Wrap(err, "Failed to initialize a new S3 repository")) } defer utils.CloseRepo(ctx, r) @@ -155,7 +156,7 @@ func initS3Cmd(cmd *cobra.Command, args []string) error { Infof(ctx, "Initialized a S3 repository within bucket %s.", s3Cfg.Bucket) if err = config.WriteRepoConfig(ctx, s3Cfg, m365, r.GetID()); err != nil { - return Only(ctx, errors.Wrap(err, "Failed to write repository configuration")) + return Only(ctx, clues.Wrap(err, "Failed to write repository configuration")) } return nil @@ -192,24 +193,24 @@ func connectS3Cmd(cmd *cobra.Command, args []string) error { s3Cfg, err := cfg.Storage.S3Config() if err != nil { - return Only(ctx, errors.Wrap(err, "Retrieving s3 configuration")) + return Only(ctx, clues.Wrap(err, "Retrieving s3 configuration")) } m365, err := cfg.Account.M365Config() if err != nil { - return Only(ctx, errors.Wrap(err, "Failed to parse m365 account config")) + return Only(ctx, clues.Wrap(err, "Failed to parse m365 account config")) } if strings.HasPrefix(s3Cfg.Endpoint, "http://") || strings.HasPrefix(s3Cfg.Endpoint, "https://") { invalidEndpointErr := "endpoint doesn't support specifying protocol. " + "pass --disable-tls flag to use http:// instead of default https://" - return Only(ctx, errors.New(invalidEndpointErr)) + return Only(ctx, clues.New(invalidEndpointErr)) } r, err := repository.ConnectAndSendConnectEvent(ctx, cfg.Account, cfg.Storage, options.Control()) if err != nil { - return Only(ctx, errors.Wrap(err, "Failed to connect to the S3 repository")) + return Only(ctx, clues.Wrap(err, "Failed to connect to the S3 repository")) } defer utils.CloseRepo(ctx, r) @@ -217,7 +218,7 @@ func connectS3Cmd(cmd *cobra.Command, args []string) error { Infof(ctx, "Connected to S3 bucket %s.", s3Cfg.Bucket) if err = config.WriteRepoConfig(ctx, s3Cfg, m365, r.GetID()); err != nil { - return Only(ctx, errors.Wrap(err, "Failed to write repository configuration")) + return Only(ctx, clues.Wrap(err, "Failed to write repository configuration")) } return nil diff --git a/src/cli/repo/s3_e2e_test.go b/src/cli/repo/s3_e2e_test.go index fc4f5debd..4266be8f0 100644 --- a/src/cli/repo/s3_e2e_test.go +++ b/src/cli/repo/s3_e2e_test.go @@ -4,11 +4,11 @@ import ( "os" "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/cli" "github.com/alcionai/corso/src/cli/config" "github.com/alcionai/corso/src/internal/tester" diff --git a/src/cli/restore/exchange.go b/src/cli/restore/exchange.go index 02f1916b5..d31b67a71 100644 --- a/src/cli/restore/exchange.go +++ b/src/cli/restore/exchange.go @@ -1,6 +1,7 @@ package restore import ( + "github.com/alcionai/clues" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -138,7 +139,7 @@ func restoreExchangeCmd(cmd *cobra.Command, args []string) error { r, err := repository.Connect(ctx, cfg.Account, cfg.Storage, options.Control()) if err != nil { - return Only(ctx, errors.Wrapf(err, "Failed to connect to the %s repository", cfg.Storage.Provider)) + return Only(ctx, clues.Wrap(err, "Failed to connect to the "+cfg.Storage.Provider.String()+" repository")) } defer utils.CloseRepo(ctx, r) @@ -151,16 +152,16 @@ func restoreExchangeCmd(cmd *cobra.Command, args []string) error { ro, err := r.NewRestore(ctx, utils.BackupID, sel.Selector, dest) if err != nil { - return Only(ctx, errors.Wrap(err, "Failed to initialize Exchange restore")) + return Only(ctx, clues.Wrap(err, "Failed to initialize Exchange restore")) } ds, err := ro.Run(ctx) if err != nil { if errors.Is(err, data.ErrNotFound) { - return Only(ctx, errors.Errorf("Backup or backup details missing for id %s", utils.BackupID)) + return Only(ctx, clues.New("Backup or backup details missing for id "+utils.BackupID)) } - return Only(ctx, errors.Wrap(err, "Failed to run Exchange restore")) + return Only(ctx, clues.Wrap(err, "Failed to run Exchange restore")) } ds.PrintEntries(ctx) diff --git a/src/cli/restore/exchange_e2e_test.go b/src/cli/restore/exchange_e2e_test.go index ccd973fe9..2c03fd6bb 100644 --- a/src/cli/restore/exchange_e2e_test.go +++ b/src/cli/restore/exchange_e2e_test.go @@ -4,11 +4,11 @@ import ( "context" "testing" + "github.com/alcionai/clues" "github.com/spf13/viper" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/cli" "github.com/alcionai/corso/src/cli/config" "github.com/alcionai/corso/src/cli/utils" diff --git a/src/cli/restore/onedrive.go b/src/cli/restore/onedrive.go index b0aaca1eb..54ef1d409 100644 --- a/src/cli/restore/onedrive.go +++ b/src/cli/restore/onedrive.go @@ -1,6 +1,7 @@ package restore import ( + "github.com/alcionai/clues" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -103,7 +104,7 @@ func restoreOneDriveCmd(cmd *cobra.Command, args []string) error { r, err := repository.Connect(ctx, cfg.Account, cfg.Storage, options.Control()) if err != nil { - return Only(ctx, errors.Wrapf(err, "Failed to connect to the %s repository", cfg.Storage.Provider)) + return Only(ctx, clues.Wrap(err, "Failed to connect to the "+cfg.Storage.Provider.String()+" repository")) } defer utils.CloseRepo(ctx, r) @@ -116,16 +117,16 @@ func restoreOneDriveCmd(cmd *cobra.Command, args []string) error { ro, err := r.NewRestore(ctx, utils.BackupID, sel.Selector, dest) if err != nil { - return Only(ctx, errors.Wrap(err, "Failed to initialize OneDrive restore")) + return Only(ctx, clues.Wrap(err, "Failed to initialize OneDrive restore")) } ds, err := ro.Run(ctx) if err != nil { if errors.Is(err, data.ErrNotFound) { - return Only(ctx, errors.Errorf("Backup or backup details missing for id %s", utils.BackupID)) + return Only(ctx, clues.New("Backup or backup details missing for id "+utils.BackupID)) } - return Only(ctx, errors.Wrap(err, "Failed to run OneDrive restore")) + return Only(ctx, clues.Wrap(err, "Failed to run OneDrive restore")) } ds.PrintEntries(ctx) diff --git a/src/cli/restore/sharepoint.go b/src/cli/restore/sharepoint.go index 410e87c3f..1d74cdb61 100644 --- a/src/cli/restore/sharepoint.go +++ b/src/cli/restore/sharepoint.go @@ -1,6 +1,7 @@ package restore import ( + "github.com/alcionai/clues" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -117,7 +118,7 @@ func restoreSharePointCmd(cmd *cobra.Command, args []string) error { r, err := repository.Connect(ctx, cfg.Account, cfg.Storage, options.Control()) if err != nil { - return Only(ctx, errors.Wrapf(err, "Failed to connect to the %s repository", cfg.Storage.Provider)) + return Only(ctx, clues.Wrap(err, "Failed to connect to the "+cfg.Storage.Provider.String()+" repository")) } defer utils.CloseRepo(ctx, r) @@ -130,16 +131,16 @@ func restoreSharePointCmd(cmd *cobra.Command, args []string) error { ro, err := r.NewRestore(ctx, utils.BackupID, sel.Selector, dest) if err != nil { - return Only(ctx, errors.Wrap(err, "Failed to initialize SharePoint restore")) + return Only(ctx, clues.Wrap(err, "Failed to initialize SharePoint restore")) } ds, err := ro.Run(ctx) if err != nil { if errors.Is(err, data.ErrNotFound) { - return Only(ctx, errors.Errorf("Backup or backup details missing for id %s", utils.BackupID)) + return Only(ctx, clues.New("Backup or backup details missing for id "+utils.BackupID)) } - return Only(ctx, errors.Wrap(err, "Failed to run SharePoint restore")) + return Only(ctx, clues.Wrap(err, "Failed to run SharePoint restore")) } ds.PrintEntries(ctx) diff --git a/src/cli/utils/exchange.go b/src/cli/utils/exchange.go index 53b845d43..63a815d0a 100644 --- a/src/cli/utils/exchange.go +++ b/src/cli/utils/exchange.go @@ -1,10 +1,10 @@ package utils import ( - "errors" + "github.com/alcionai/clues" + "github.com/spf13/cobra" "github.com/alcionai/corso/src/pkg/selectors" - "github.com/spf13/cobra" ) // flag names @@ -197,27 +197,27 @@ func AddExchangeInfo( // ValidateExchangeRestoreFlags checks common flags for correctness and interdependencies func ValidateExchangeRestoreFlags(backupID string, opts ExchangeOpts) error { if len(backupID) == 0 { - return errors.New("a backup ID is required") + return clues.New("a backup ID is required") } if _, ok := opts.Populated[EmailReceivedAfterFN]; ok && !IsValidTimeFormat(opts.EmailReceivedAfter) { - return errors.New("invalid time format for email-received-after") + return clues.New("invalid time format for email-received-after") } if _, ok := opts.Populated[EmailReceivedBeforeFN]; ok && !IsValidTimeFormat(opts.EmailReceivedBefore) { - return errors.New("invalid time format for email-received-before") + return clues.New("invalid time format for email-received-before") } if _, ok := opts.Populated[EventStartsAfterFN]; ok && !IsValidTimeFormat(opts.EventStartsAfter) { - return errors.New("invalid time format for event-starts-after") + return clues.New("invalid time format for event-starts-after") } if _, ok := opts.Populated[EventStartsBeforeFN]; ok && !IsValidTimeFormat(opts.EventStartsBefore) { - return errors.New("invalid time format for event-starts-before") + return clues.New("invalid time format for event-starts-before") } if _, ok := opts.Populated[EventRecursFN]; ok && !IsValidBool(opts.EventRecurs) { - return errors.New("invalid format for event-recurs") + return clues.New("invalid format for event-recurs") } return nil diff --git a/src/cli/utils/exchange_test.go b/src/cli/utils/exchange_test.go index 5f560f4b3..b9f7f64ca 100644 --- a/src/cli/utils/exchange_test.go +++ b/src/cli/utils/exchange_test.go @@ -3,10 +3,10 @@ package utils_test import ( "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/cli/utils" "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/tester" diff --git a/src/cli/utils/onedrive.go b/src/cli/utils/onedrive.go index 06631c4dc..0b4a2e489 100644 --- a/src/cli/utils/onedrive.go +++ b/src/cli/utils/onedrive.go @@ -1,10 +1,10 @@ package utils import ( - "errors" + "github.com/alcionai/clues" + "github.com/spf13/cobra" "github.com/alcionai/corso/src/pkg/selectors" - "github.com/spf13/cobra" ) type OneDriveOpts struct { @@ -57,23 +57,23 @@ func AddOneDriveDetailsAndRestoreFlags(cmd *cobra.Command) { // ValidateOneDriveRestoreFlags checks common flags for correctness and interdependencies func ValidateOneDriveRestoreFlags(backupID string, opts OneDriveOpts) error { if len(backupID) == 0 { - return errors.New("a backup ID is required") + return clues.New("a backup ID is required") } if _, ok := opts.Populated[FileCreatedAfterFN]; ok && !IsValidTimeFormat(opts.FileCreatedAfter) { - return errors.New("invalid time format for created-after") + return clues.New("invalid time format for created-after") } if _, ok := opts.Populated[FileCreatedBeforeFN]; ok && !IsValidTimeFormat(opts.FileCreatedBefore) { - return errors.New("invalid time format for created-before") + return clues.New("invalid time format for created-before") } if _, ok := opts.Populated[FileModifiedAfterFN]; ok && !IsValidTimeFormat(opts.FileModifiedAfter) { - return errors.New("invalid time format for modified-after") + return clues.New("invalid time format for modified-after") } if _, ok := opts.Populated[FileModifiedBeforeFN]; ok && !IsValidTimeFormat(opts.FileModifiedBefore) { - return errors.New("invalid time format for modified-before") + return clues.New("invalid time format for modified-before") } return nil diff --git a/src/cli/utils/sharepoint.go b/src/cli/utils/sharepoint.go index 8a99537b9..3844bcccf 100644 --- a/src/cli/utils/sharepoint.go +++ b/src/cli/utils/sharepoint.go @@ -1,10 +1,10 @@ package utils import ( - "errors" + "github.com/alcionai/clues" + "github.com/spf13/cobra" "github.com/alcionai/corso/src/pkg/selectors" - "github.com/spf13/cobra" ) const ( @@ -97,23 +97,23 @@ func AddSharePointDetailsAndRestoreFlags(cmd *cobra.Command) { // ValidateSharePointRestoreFlags checks common flags for correctness and interdependencies func ValidateSharePointRestoreFlags(backupID string, opts SharePointOpts) error { if len(backupID) == 0 { - return errors.New("a backup ID is required") + return clues.New("a backup ID is required") } if _, ok := opts.Populated[FileCreatedAfterFN]; ok && !IsValidTimeFormat(opts.FileCreatedAfter) { - return errors.New("invalid time format for " + FileCreatedAfterFN) + return clues.New("invalid time format for " + FileCreatedAfterFN) } if _, ok := opts.Populated[FileCreatedBeforeFN]; ok && !IsValidTimeFormat(opts.FileCreatedBefore) { - return errors.New("invalid time format for " + FileCreatedBeforeFN) + return clues.New("invalid time format for " + FileCreatedBeforeFN) } if _, ok := opts.Populated[FileModifiedAfterFN]; ok && !IsValidTimeFormat(opts.FileModifiedAfter) { - return errors.New("invalid time format for " + FileModifiedAfterFN) + return clues.New("invalid time format for " + FileModifiedAfterFN) } if _, ok := opts.Populated[FileModifiedBeforeFN]; ok && !IsValidTimeFormat(opts.FileModifiedBefore) { - return errors.New("invalid time format for " + FileModifiedBeforeFN) + return clues.New("invalid time format for " + FileModifiedBeforeFN) } return nil diff --git a/src/cli/utils/testdata/opts.go b/src/cli/utils/testdata/opts.go index 3d54bb07e..5576f7c38 100644 --- a/src/cli/utils/testdata/opts.go +++ b/src/cli/utils/testdata/opts.go @@ -2,9 +2,10 @@ package testdata import ( "context" - "errors" "time" + "github.com/alcionai/clues" + "github.com/alcionai/corso/src/cli/utils" "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/model" @@ -560,21 +561,21 @@ func (MockBackupGetter) Backup( context.Context, model.StableID, ) (*backup.Backup, error) { - return nil, errors.New("unexpected call to mock") + return nil, clues.New("unexpected call to mock") } func (MockBackupGetter) Backups( context.Context, []model.StableID, ) ([]*backup.Backup, *fault.Bus) { - return nil, fault.New(false).Fail(errors.New("unexpected call to mock")) + return nil, fault.New(false).Fail(clues.New("unexpected call to mock")) } func (MockBackupGetter) BackupsByTag( context.Context, ...store.FilterOption, ) ([]*backup.Backup, error) { - return nil, errors.New("unexpected call to mock") + return nil, clues.New("unexpected call to mock") } func (bg *MockBackupGetter) GetBackupDetails( @@ -585,7 +586,7 @@ func (bg *MockBackupGetter) GetBackupDetails( return testdata.GetDetailsSet(), nil, fault.New(true) } - return nil, nil, fault.New(false).Fail(errors.New("unexpected call to mock")) + return nil, nil, fault.New(false).Fail(clues.New("unexpected call to mock")) } func (bg *MockBackupGetter) GetBackupErrors( @@ -597,5 +598,5 @@ func (bg *MockBackupGetter) GetBackupErrors( return &fe, nil, fault.New(true) } - return nil, nil, fault.New(false).Fail(errors.New("unexpected call to mock")) + return nil, nil, fault.New(false).Fail(clues.New("unexpected call to mock")) } diff --git a/src/cli/utils/utils.go b/src/cli/utils/utils.go index 5b6c268dd..9e829bf05 100644 --- a/src/cli/utils/utils.go +++ b/src/cli/utils/utils.go @@ -2,9 +2,9 @@ package utils import ( "context" - "errors" "fmt" + "github.com/alcionai/clues" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -26,7 +26,7 @@ const ( func RequireProps(props map[string]string) error { for name, val := range props { if len(val) == 0 { - return errors.New(name + " is required to perform this command") + return clues.New(name + " is required to perform this command") } } diff --git a/src/cli/utils/utils_test.go b/src/cli/utils/utils_test.go index 7c0b01c52..f942e61f3 100644 --- a/src/cli/utils/utils_test.go +++ b/src/cli/utils/utils_test.go @@ -3,10 +3,10 @@ package utils import ( "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/selectors" ) diff --git a/src/cmd/factory/impl/common.go b/src/cmd/factory/impl/common.go index bb53afc50..f9fe6d1a7 100644 --- a/src/cmd/factory/impl/common.go +++ b/src/cmd/factory/impl/common.go @@ -8,7 +8,6 @@ import ( "github.com/alcionai/clues" "github.com/google/uuid" - "github.com/pkg/errors" "github.com/alcionai/corso/src/cli/print" "github.com/alcionai/corso/src/internal/common" @@ -34,9 +33,9 @@ var ( User string ) -// TODO: ErrGenerating = errors.New("not all items were successfully generated") +// TODO: ErrGenerating = clues.New("not all items were successfully generated") -var ErrNotYetImplemeted = errors.New("not yet implemented") +var ErrNotYetImplemeted = clues.New("not yet implemented") // ------------------------------------------------------------------------------------------ // Restoration @@ -115,7 +114,7 @@ func getGCAndVerifyUser(ctx context.Context, userID string) (*connector.GraphCon acct, err := account.NewAccount(account.ProviderM365, m365Cfg) if err != nil { - return nil, account.Account{}, errors.Wrap(err, "finding m365 account details") + return nil, account.Account{}, clues.Wrap(err, "finding m365 account details") } // build a graph connector @@ -133,7 +132,7 @@ func getGCAndVerifyUser(ctx context.Context, userID string) (*connector.GraphCon } if _, ok := normUsers[strings.ToLower(User)]; !ok { - return nil, account.Account{}, errors.New("user not found within tenant") + return nil, account.Account{}, clues.New("user not found within tenant") } gc, err := connector.NewGraphConnector( @@ -143,7 +142,7 @@ func getGCAndVerifyUser(ctx context.Context, userID string) (*connector.GraphCon connector.Users, errs) if err != nil { - return nil, account.Account{}, errors.Wrap(err, "connecting to graph api") + return nil, account.Account{}, clues.Wrap(err, "connecting to graph api") } return gc, acct, nil diff --git a/src/cmd/getM365/getItem.go b/src/cmd/getM365/getItem.go index 8846adc76..829c70b1a 100644 --- a/src/cmd/getM365/getItem.go +++ b/src/cmd/getM365/getItem.go @@ -9,9 +9,9 @@ import ( "fmt" "os" + "github.com/alcionai/clues" "github.com/microsoft/kiota-abstractions-go/serialization" kw "github.com/microsoft/kiota-serialization-json-go" - "github.com/pkg/errors" "github.com/spf13/cobra" . "github.com/alcionai/corso/src/cli/print" @@ -83,7 +83,7 @@ func handleGetCommand(cmd *cobra.Command, args []string) error { err = runDisplayM365JSON(ctx, creds, user, m365ID, fault.New(true)) if err != nil { - return Only(ctx, errors.Wrapf(err, "unable to create mock from M365: %s", m365ID)) + return Only(ctx, clues.Wrap(err, "Error displaying item: "+m365ID)) } return nil @@ -126,12 +126,12 @@ func runDisplayM365JSON( err = sw.WriteStringValue("", &str) if err != nil { - return errors.Wrapf(err, "unable to %s to string value", itemID) + return clues.Wrap(err, "Error writing string value: "+itemID) } array, err := sw.GetSerializedContent() if err != nil { - return errors.Wrapf(err, "unable to serialize new value from M365:%s", itemID) + return clues.Wrap(err, "Error serializing item: "+itemID) } fmt.Println(string(array)) @@ -160,7 +160,7 @@ func getItem( ) ([]byte, error) { sp, _, err := itm.GetItem(ctx, user, itemID, errs) if err != nil { - return nil, errors.Wrap(err, "getting item") + return nil, clues.Wrap(err, "getting item") } return itm.Serialize(ctx, sp, user, itemID) @@ -179,7 +179,7 @@ func getGC(ctx context.Context) (*connector.GraphConnector, account.M365Config, acct, err := account.NewAccount(account.ProviderM365, m365Cfg) if err != nil { - return nil, m365Cfg, Only(ctx, errors.Wrap(err, "finding m365 account details")) + return nil, m365Cfg, Only(ctx, clues.Wrap(err, "finding m365 account details")) } // TODO: log/print recoverable errors @@ -187,7 +187,7 @@ func getGC(ctx context.Context) (*connector.GraphConnector, account.M365Config, gc, err := connector.NewGraphConnector(ctx, graph.HTTPClient(graph.NoTimeout()), acct, connector.Users, errs) if err != nil { - return nil, m365Cfg, Only(ctx, errors.Wrap(err, "connecting to graph API")) + return nil, m365Cfg, Only(ctx, clues.Wrap(err, "connecting to graph API")) } return gc, m365Cfg, nil diff --git a/src/cmd/mdgen/mdgen.go b/src/cmd/mdgen/mdgen.go index d7396806c..3e644e207 100644 --- a/src/cmd/mdgen/mdgen.go +++ b/src/cmd/mdgen/mdgen.go @@ -8,6 +8,7 @@ import ( "path/filepath" "strings" + "github.com/alcionai/clues" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -45,35 +46,35 @@ func main() { func genDocs(cmd *cobra.Command, args []string) { if err := makeDir(cliMarkdownDir); err != nil { - fatal(errors.Wrap(err, "preparing directory for markdown generation")) + fatal(clues.Wrap(err, "preparing directory for markdown generation")) } corsoCmd := cli.CorsoCommand() err := genMarkdownCorso(corsoCmd, cliMarkdownDir) if err != nil { - fatal(errors.Wrap(err, "generating the Corso CLI markdown")) + fatal(clues.Wrap(err, "generating the Corso CLI markdown")) } } func makeDir(dir string) error { wd, err := os.Getwd() if err != nil { - return errors.Wrap(err, "finding current working directory") + return clues.Wrap(err, "finding current working directory") } if !strings.HasSuffix(wd, "/src") { - return errors.New("must be called from /corso/src") + return clues.New("must be called from /corso/src") } _, err = os.Stat(dir) if err != nil && !errors.Is(err, os.ErrNotExist) { - return errors.Wrap(err, "unable to discover directory") + return clues.Wrap(err, "unable to discover directory") } if errors.Is(err, os.ErrNotExist) { if err := os.Mkdir(dir, os.ModePerm); err != nil { - return errors.Wrap(err, "generating directory to hold markdown") + return clues.Wrap(err, "generating directory to hold markdown") } } diff --git a/src/cmd/purge/purge.go b/src/cmd/purge/purge.go index 3f5747cf6..af7b3067d 100644 --- a/src/cmd/purge/purge.go +++ b/src/cmd/purge/purge.go @@ -6,10 +6,10 @@ import ( "time" "github.com/alcionai/clues" + . "github.com/alcionai/corso/src/cli/print" "github.com/pkg/errors" "github.com/spf13/cobra" - . "github.com/alcionai/corso/src/cli/print" "github.com/alcionai/corso/src/cli/utils" "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/connector" @@ -41,7 +41,7 @@ var ( prefix string ) -var ErrPurging = errors.New("not all items were successfully purged") +var ErrPurging = clues.New("not all items were successfully purged") // ------------------------------------------------------------------------------------------ // CLI command handlers @@ -109,7 +109,7 @@ func handleOneDriveFolderPurge(cmd *cobra.Command, args []string) error { if err := runPurgeForEachUser(ctx, acct, gc, t, purgeOneDriveFolders); err != nil { logger.Ctx(ctx).Error(err) - return Only(ctx, errors.Wrap(ErrPurging, "OneDrive folders")) + return Only(ctx, clues.Wrap(ErrPurging, "OneDrive folders")) } return nil @@ -182,7 +182,7 @@ func purgeOneDriveFolders( deleter := func(gs graph.Servicer, uid string, f purgable) error { driveFolder, ok := f.(*onedrive.Displayable) if !ok { - return errors.New("non-OneDrive item") + return clues.New("non-OneDrive item") } return onedrive.DeleteItem( @@ -211,7 +211,7 @@ func purgeFolders( // get them folders fs, err := getter(gc.Service, uid, prefix) if err != nil { - return Only(ctx, errors.Wrapf(err, "retrieving %s folders", data)) + return Only(ctx, clues.Wrap(err, "retrieving folders: "+data)) } if len(fs) == 0 { @@ -228,7 +228,7 @@ func purgeFolders( dnTime, err := common.ExtractTime(displayName) if err != nil && !errors.Is(err, common.ErrNoTimeString) { - err = errors.Wrapf(err, "!! Error: parsing container named [%s]", displayName) + err = clues.Wrap(err, "!! Error: parsing container: "+displayName) Info(ctx, err) return err @@ -242,7 +242,7 @@ func purgeFolders( err = deleter(gc.Service, uid, fld) if err != nil { - err = errors.Wrapf(err, "!! Error") + err = clues.Wrap(err, "!! Error") Info(ctx, err) } } @@ -263,7 +263,7 @@ func getGC(ctx context.Context) (account.Account, *connector.GraphConnector, err acct, err := account.NewAccount(account.ProviderM365, m365Cfg) if err != nil { - return account.Account{}, nil, Only(ctx, errors.Wrap(err, "finding m365 account details")) + return account.Account{}, nil, Only(ctx, clues.Wrap(err, "finding m365 account details")) } // build a graph connector @@ -272,7 +272,7 @@ func getGC(ctx context.Context) (account.Account, *connector.GraphConnector, err gc, err := connector.NewGraphConnector(ctx, graph.HTTPClient(graph.NoTimeout()), acct, connector.Users, errs) if err != nil { - return account.Account{}, nil, Only(ctx, errors.Wrap(err, "connecting to graph api")) + return account.Account{}, nil, Only(ctx, clues.Wrap(err, "connecting to graph api")) } return acct, gc, nil @@ -288,7 +288,7 @@ func getBoundaryTime(ctx context.Context) (time.Time, error) { if len(before) > 0 { boundaryTime, err = common.ParseTime(before) if err != nil { - return time.Time{}, Only(ctx, errors.Wrap(err, "parsing before flag to time")) + return time.Time{}, Only(ctx, clues.Wrap(err, "parsing before flag to time")) } } diff --git a/src/internal/common/configs_test.go b/src/internal/common/configs_test.go index 01d1cc98a..9128624c5 100644 --- a/src/internal/common/configs_test.go +++ b/src/internal/common/configs_test.go @@ -3,10 +3,10 @@ package common_test import ( "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/tester" ) diff --git a/src/internal/common/crash/crash_test.go b/src/internal/common/crash/crash_test.go index 651d4afed..09a6559b9 100644 --- a/src/internal/common/crash/crash_test.go +++ b/src/internal/common/crash/crash_test.go @@ -4,10 +4,11 @@ import ( "testing" "github.com/alcionai/clues" - "github.com/alcionai/corso/src/internal/common/crash" - "github.com/alcionai/corso/src/internal/tester" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" + + "github.com/alcionai/corso/src/internal/common/crash" + "github.com/alcionai/corso/src/internal/tester" ) type CrashTestDummySuite struct { diff --git a/src/internal/common/time.go b/src/internal/common/time.go index f747bef4c..9a39a2a02 100644 --- a/src/internal/common/time.go +++ b/src/internal/common/time.go @@ -5,7 +5,6 @@ import ( "time" "github.com/alcionai/clues" - "github.com/pkg/errors" ) type TimeFormat string @@ -87,8 +86,8 @@ var ( ) var ( - ErrNoTimeString = errors.New("no substring contains a known time format") - errParsingStringToTime = errors.New("parsing string as time.Time") + ErrNoTimeString = clues.New("no substring contains a known time format") + errParsingStringToTime = clues.New("parsing string as time.Time") ) // Now produces the current time as a string in the standard format. @@ -136,7 +135,7 @@ func FormatLegacyTime(t time.Time) string { // the provided string. Always returns a UTC timezone value. func ParseTime(s string) (time.Time, error) { if len(s) == 0 { - return time.Time{}, clues.Stack(errParsingStringToTime, errors.New("empty string")) + return time.Time{}, clues.Stack(errParsingStringToTime, clues.New("empty string")) } for _, form := range formats { @@ -146,14 +145,14 @@ func ParseTime(s string) (time.Time, error) { } } - return time.Time{}, clues.Stack(errParsingStringToTime, errors.New(s)) + return time.Time{}, clues.Stack(errParsingStringToTime, clues.New(s)) } // ExtractTime greedily retrieves a timestamp substring from the provided string. // returns ErrNoTimeString if no match is found. func ExtractTime(s string) (time.Time, error) { if len(s) == 0 { - return time.Time{}, clues.Stack(errParsingStringToTime, errors.New("empty string")) + return time.Time{}, clues.Stack(errParsingStringToTime, clues.New("empty string")) } for _, re := range regexes { @@ -163,5 +162,5 @@ func ExtractTime(s string) (time.Time, error) { } } - return time.Time{}, clues.Stack(ErrNoTimeString, errors.New(s)) + return time.Time{}, clues.Stack(ErrNoTimeString, clues.New(s)) } diff --git a/src/internal/common/time_test.go b/src/internal/common/time_test.go index bfb784a93..6c58f7555 100644 --- a/src/internal/common/time_test.go +++ b/src/internal/common/time_test.go @@ -4,11 +4,11 @@ import ( "testing" "time" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/tester" ) diff --git a/src/internal/connector/data_collections.go b/src/internal/connector/data_collections.go index ddf81672c..97e810e88 100644 --- a/src/internal/connector/data_collections.go +++ b/src/internal/connector/data_collections.go @@ -4,9 +4,8 @@ import ( "context" "strings" - "github.com/pkg/errors" - "github.com/alcionai/clues" + "github.com/alcionai/corso/src/internal/connector/discovery" "github.com/alcionai/corso/src/internal/connector/discovery/api" "github.com/alcionai/corso/src/internal/connector/exchange" @@ -212,7 +211,7 @@ func (gc *GraphConnector) RestoreDataCollections( creds, err := acct.M365Config() if err != nil { - return nil, errors.Wrap(err, "malformed azure credentials") + return nil, clues.Wrap(err, "malformed azure credentials") } switch selector.Service { diff --git a/src/internal/connector/data_collections_test.go b/src/internal/connector/data_collections_test.go index 8a4c18f39..44cffd192 100644 --- a/src/internal/connector/data_collections_test.go +++ b/src/internal/connector/data_collections_test.go @@ -5,11 +5,11 @@ import ( "io" "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/exchange" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/sharepoint" diff --git a/src/internal/connector/discovery/api/api.go b/src/internal/connector/discovery/api/api.go index 6e623c4d2..efcf48159 100644 --- a/src/internal/connector/discovery/api/api.go +++ b/src/internal/connector/discovery/api/api.go @@ -1,7 +1,7 @@ package api import ( - "github.com/pkg/errors" + "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/pkg/account" @@ -49,7 +49,7 @@ func newService(creds account.M365Config) (*graph.Service, error) { creds.AzureClientID, creds.AzureClientSecret) if err != nil { - return nil, errors.Wrap(err, "generating graph api service client") + return nil, clues.Wrap(err, "generating graph api service client") } return graph.NewService(adapter), nil diff --git a/src/internal/connector/discovery/api/beta_service.go b/src/internal/connector/discovery/api/beta_service.go index 0208ace69..d902f1553 100644 --- a/src/internal/connector/discovery/api/beta_service.go +++ b/src/internal/connector/discovery/api/beta_service.go @@ -1,9 +1,9 @@ package api import ( + "github.com/alcionai/clues" absser "github.com/microsoft/kiota-abstractions-go/serialization" msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go" - "github.com/pkg/errors" "github.com/alcionai/corso/src/internal/connector/graph/betasdk" ) @@ -32,12 +32,12 @@ func (s BetaService) Serialize(object absser.Parsable) ([]byte, error) { GetSerializationWriterFactory(). GetSerializationWriter("application/json") if err != nil || writer == nil { - return nil, errors.Wrap(err, "creating json serialization writer") + return nil, clues.Wrap(err, "creating json serialization writer") } err = writer.WriteObjectValue("", object) if err != nil { - return nil, errors.Wrap(err, "writeObjecValue serialization") + return nil, clues.Wrap(err, "writeObjecValue serialization") } return writer.GetSerializedContent() diff --git a/src/internal/connector/discovery/api/beta_service_test.go b/src/internal/connector/discovery/api/beta_service_test.go index 90ffd1972..802719f8e 100644 --- a/src/internal/connector/discovery/api/beta_service_test.go +++ b/src/internal/connector/discovery/api/beta_service_test.go @@ -3,11 +3,11 @@ package api import ( "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/graph/betasdk/models" "github.com/alcionai/corso/src/internal/tester" diff --git a/src/internal/connector/discovery/api/users.go b/src/internal/connector/discovery/api/users.go index ea4b268f6..932599a21 100644 --- a/src/internal/connector/discovery/api/users.go +++ b/src/internal/connector/discovery/api/users.go @@ -2,13 +2,13 @@ package api import ( "context" + "fmt" "github.com/alcionai/clues" absser "github.com/microsoft/kiota-abstractions-go" msgraphgocore "github.com/microsoftgraph/msgraph-sdk-go-core" "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/microsoftgraph/msgraph-sdk-go/users" - "github.com/pkg/errors" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/pkg/fault" @@ -182,7 +182,7 @@ func (c Users) GetInfo(ctx context.Context, userID string) (*UserInfo, error) { func validateUser(item any) (models.Userable, error) { m, ok := item.(models.Userable) if !ok { - return nil, clues.Stack(clues.New("unexpected model"), errors.Errorf("%T", item)) + return nil, clues.New(fmt.Sprintf("unexpected model: %T", item)) } if m.GetId() == nil { diff --git a/src/internal/connector/discovery/api/users_test.go b/src/internal/connector/discovery/api/users_test.go index b92a16211..ebbd75a34 100644 --- a/src/internal/connector/discovery/api/users_test.go +++ b/src/internal/connector/discovery/api/users_test.go @@ -3,11 +3,11 @@ package api import ( "testing" + "github.com/alcionai/clues" "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/tester" ) diff --git a/src/internal/connector/discovery/discovery.go b/src/internal/connector/discovery/discovery.go index 1ecf85aa5..ab1efba60 100644 --- a/src/internal/connector/discovery/discovery.go +++ b/src/internal/connector/discovery/discovery.go @@ -6,7 +6,6 @@ import ( "github.com/alcionai/clues" "github.com/microsoftgraph/msgraph-sdk-go/models" - "github.com/pkg/errors" "github.com/alcionai/corso/src/internal/connector/discovery/api" "github.com/alcionai/corso/src/internal/connector/graph" @@ -61,12 +60,12 @@ func User(ctx context.Context, gwi getWithInfoer, userID string) (models.Userabl return nil, nil, fmt.Errorf("resource owner [%s] not found within tenant", userID) } - return nil, nil, errors.Wrap(err, "getting user") + return nil, nil, clues.Wrap(err, "getting user") } ui, err := gwi.GetInfo(ctx, userID) if err != nil { - return nil, nil, errors.Wrap(err, "getting user info") + return nil, nil, clues.Wrap(err, "getting user info") } return u, ui, nil diff --git a/src/internal/connector/discovery/discovery_test.go b/src/internal/connector/discovery/discovery_test.go index 0c62829ea..c9a2c3f48 100644 --- a/src/internal/connector/discovery/discovery_test.go +++ b/src/internal/connector/discovery/discovery_test.go @@ -3,11 +3,11 @@ package discovery_test import ( "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/discovery" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/account" diff --git a/src/internal/connector/exchange/api/api.go b/src/internal/connector/exchange/api/api.go index 7c4622bdf..831f71d99 100644 --- a/src/internal/connector/exchange/api/api.go +++ b/src/internal/connector/exchange/api/api.go @@ -7,7 +7,6 @@ import ( "github.com/alcionai/clues" "github.com/microsoft/kiota-abstractions-go/serialization" "github.com/microsoftgraph/msgraph-sdk-go/models" - "github.com/pkg/errors" "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/graph" @@ -95,7 +94,7 @@ func newService(creds account.M365Config) (*graph.Service, error) { creds.AzureClientID, creds.AzureClientSecret) if err != nil { - return nil, errors.Wrap(err, "generating no-timeout graph adapter") + return nil, clues.Wrap(err, "generating no-timeout graph adapter") } return graph.NewService(a), nil @@ -108,7 +107,7 @@ func newLargeItemService(creds account.M365Config) (*graph.Service, error) { creds.AzureClientSecret, graph.NoTimeout()) if err != nil { - return nil, errors.Wrap(err, "generating no-timeout graph adapter") + return nil, clues.Wrap(err, "generating no-timeout graph adapter") } return graph.NewService(a), nil @@ -123,7 +122,7 @@ func newLargeItemService(creds account.M365Config) (*graph.Service, error) { func checkIDAndName(c graph.Container) error { id := ptr.Val(c.GetId()) if len(id) == 0 { - return errors.New("container missing ID") + return clues.New("container missing ID") } dn := ptr.Val(c.GetDisplayName()) diff --git a/src/internal/connector/exchange/api/api_test.go b/src/internal/connector/exchange/api/api_test.go index 9c63f1333..c5708f159 100644 --- a/src/internal/connector/exchange/api/api_test.go +++ b/src/internal/connector/exchange/api/api_test.go @@ -3,12 +3,12 @@ package api import ( "testing" + "github.com/alcionai/clues" "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/mockconnector" "github.com/alcionai/corso/src/internal/connector/support" diff --git a/src/internal/connector/exchange/api/events_test.go b/src/internal/connector/exchange/api/events_test.go index c7ff89329..7482aad3f 100644 --- a/src/internal/connector/exchange/api/events_test.go +++ b/src/internal/connector/exchange/api/events_test.go @@ -4,12 +4,12 @@ import ( "testing" "time" + "github.com/alcionai/clues" "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/connector/mockconnector" "github.com/alcionai/corso/src/internal/connector/support" diff --git a/src/internal/connector/exchange/attachment.go b/src/internal/connector/exchange/attachment.go index 38501fe72..019699e77 100644 --- a/src/internal/connector/exchange/attachment.go +++ b/src/internal/connector/exchange/attachment.go @@ -5,9 +5,9 @@ import ( "context" "io" + "github.com/alcionai/clues" "github.com/microsoftgraph/msgraph-sdk-go/models" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/support" "github.com/alcionai/corso/src/internal/connector/uploadsession" diff --git a/src/internal/connector/exchange/cache_container.go b/src/internal/connector/exchange/cache_container.go index 1da43d994..acad82a31 100644 --- a/src/internal/connector/exchange/cache_container.go +++ b/src/internal/connector/exchange/cache_container.go @@ -1,9 +1,8 @@ package exchange import ( - "github.com/pkg/errors" - "github.com/alcionai/clues" + "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/graph" ) @@ -13,7 +12,7 @@ import ( func checkIDAndName(c graph.Container) error { id, ok := ptr.ValOK(c.GetId()) if !ok { - return errors.New("container missing ID") + return clues.New("container missing ID") } if _, ok := ptr.ValOK(c.GetDisplayName()); !ok { diff --git a/src/internal/connector/exchange/contact_folder_cache.go b/src/internal/connector/exchange/contact_folder_cache.go index 615afec15..2e7b313c8 100644 --- a/src/internal/connector/exchange/contact_folder_cache.go +++ b/src/internal/connector/exchange/contact_folder_cache.go @@ -4,7 +4,6 @@ import ( "context" "github.com/alcionai/clues" - "github.com/pkg/errors" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/pkg/fault" @@ -52,16 +51,16 @@ func (cfc *contactFolderCache) Populate( baseContainerPather ...string, ) error { if err := cfc.init(ctx, baseID, baseContainerPather); err != nil { - return errors.Wrap(err, "initializing") + return clues.Wrap(err, "initializing") } err := cfc.enumer.EnumerateContainers(ctx, cfc.userID, baseID, cfc.addFolder, errs) if err != nil { - return errors.Wrap(err, "enumerating containers") + return clues.Wrap(err, "enumerating containers") } if err := cfc.populatePaths(ctx, false, errs); err != nil { - return errors.Wrap(err, "populating paths") + return clues.Wrap(err, "populating paths") } return nil diff --git a/src/internal/connector/exchange/container_resolver.go b/src/internal/connector/exchange/container_resolver.go index 150318c56..db93d213a 100644 --- a/src/internal/connector/exchange/container_resolver.go +++ b/src/internal/connector/exchange/container_resolver.go @@ -4,7 +4,6 @@ import ( "context" "github.com/alcionai/clues" - "github.com/pkg/errors" "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/graph" @@ -87,7 +86,7 @@ func (cr *containerResolver) idToPath( depth+1, useIDInPath) if err != nil { - return nil, nil, errors.Wrap(err, "retrieving parent folder") + return nil, nil, clues.Wrap(err, "retrieving parent folder") } toAppend := ptr.Val(c.GetDisplayName()) @@ -135,11 +134,11 @@ func (cr *containerResolver) addFolder(cf graph.CacheFolder) error { // Only require a non-nil non-empty parent if the path isn't already populated. if cf.Path() != nil { if err := checkIDAndName(cf.Container); err != nil { - return errors.Wrap(err, "adding item to cache") + return clues.Wrap(err, "adding item to cache") } } else { if err := checkRequiredValues(cf.Container); err != nil { - return errors.Wrap(err, "adding item to cache") + return clues.Wrap(err, "adding item to cache") } } @@ -180,7 +179,7 @@ func (cr *containerResolver) AddToCache( // when they're made. _, _, err := cr.IDToPath(ctx, ptr.Val(f.GetId()), useIDInPath) if err != nil { - return errors.Wrap(err, "adding cache entry") + return clues.Wrap(err, "adding cache entry") } return nil diff --git a/src/internal/connector/exchange/container_resolver_test.go b/src/internal/connector/exchange/container_resolver_test.go index 3679be029..389182ebb 100644 --- a/src/internal/connector/exchange/container_resolver_test.go +++ b/src/internal/connector/exchange/container_resolver_test.go @@ -5,12 +5,12 @@ import ( stdpath "path" "testing" + "github.com/alcionai/clues" "github.com/google/uuid" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/tester" diff --git a/src/internal/connector/exchange/data_collections.go b/src/internal/connector/exchange/data_collections.go index ef20f3e59..3391b96f4 100644 --- a/src/internal/connector/exchange/data_collections.go +++ b/src/internal/connector/exchange/data_collections.go @@ -5,7 +5,6 @@ import ( "encoding/json" "github.com/alcionai/clues" - "github.com/pkg/errors" "github.com/alcionai/corso/src/internal/connector/exchange/api" "github.com/alcionai/corso/src/internal/connector/graph" @@ -286,7 +285,7 @@ func createCollections( resolver, err := PopulateExchangeContainerResolver(ctx, qp, errs) if err != nil { - return nil, errors.Wrap(err, "populating container cache") + return nil, clues.Wrap(err, "populating container cache") } err = filterContainersAndFillCollections( @@ -301,7 +300,7 @@ func createCollections( ctrlOpts, errs) if err != nil { - return nil, errors.Wrap(err, "filling collections") + return nil, clues.Wrap(err, "filling collections") } foldersComplete <- struct{}{} diff --git a/src/internal/connector/exchange/data_collections_test.go b/src/internal/connector/exchange/data_collections_test.go index fac5e636e..c75e7da51 100644 --- a/src/internal/connector/exchange/data_collections_test.go +++ b/src/internal/connector/exchange/data_collections_test.go @@ -5,11 +5,11 @@ import ( "sync" "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/exchange/api" "github.com/alcionai/corso/src/internal/connector/graph" diff --git a/src/internal/connector/exchange/event_calendar_cache.go b/src/internal/connector/exchange/event_calendar_cache.go index 5e57140bd..69fc5f2f2 100644 --- a/src/internal/connector/exchange/event_calendar_cache.go +++ b/src/internal/connector/exchange/event_calendar_cache.go @@ -4,7 +4,6 @@ import ( "context" "github.com/alcionai/clues" - "github.com/pkg/errors" "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/graph" @@ -44,7 +43,7 @@ func (ecc *eventCalendarCache) populateEventRoot(ctx context.Context) error { f, err := ecc.getter.GetContainerByID(ctx, ecc.userID, container) if err != nil { - return errors.Wrap(err, "fetching calendar") + return clues.Wrap(err, "fetching calendar") } temp := graph.NewCacheFolder( @@ -68,7 +67,7 @@ func (ecc *eventCalendarCache) Populate( baseContainerPath ...string, ) error { if err := ecc.init(ctx); err != nil { - return errors.Wrap(err, "initializing") + return clues.Wrap(err, "initializing") } err := ecc.enumer.EnumerateContainers( @@ -78,11 +77,11 @@ func (ecc *eventCalendarCache) Populate( ecc.addFolder, errs) if err != nil { - return errors.Wrap(err, "enumerating containers") + return clues.Wrap(err, "enumerating containers") } if err := ecc.populatePaths(ctx, true, errs); err != nil { - return errors.Wrap(err, "establishing calendar paths") + return clues.Wrap(err, "establishing calendar paths") } return nil @@ -116,7 +115,7 @@ func (ecc *eventCalendarCache) AddToCache(ctx context.Context, f graph.Container _, _, err := ecc.IDToPath(ctx, ptr.Val(f.GetId()), true) if err != nil { delete(ecc.newAdditions, ptr.Val(f.GetDisplayName())) - return errors.Wrap(err, "setting path to container id") + return clues.Wrap(err, "setting path to container id") } return nil diff --git a/src/internal/connector/exchange/exchange_data_collection_test.go b/src/internal/connector/exchange/exchange_data_collection_test.go index 4462bdddf..4df0bbb87 100644 --- a/src/internal/connector/exchange/exchange_data_collection_test.go +++ b/src/internal/connector/exchange/exchange_data_collection_test.go @@ -5,12 +5,12 @@ import ( "context" "testing" + "github.com/alcionai/clues" "github.com/microsoft/kiota-abstractions-go/serialization" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/data" "github.com/alcionai/corso/src/internal/tester" diff --git a/src/internal/connector/exchange/folder_resolver_test.go b/src/internal/connector/exchange/folder_resolver_test.go index 9ec6b63f3..01a852bf2 100644 --- a/src/internal/connector/exchange/folder_resolver_test.go +++ b/src/internal/connector/exchange/folder_resolver_test.go @@ -3,11 +3,11 @@ package exchange import ( "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/exchange/api" "github.com/alcionai/corso/src/internal/connector/graph" diff --git a/src/internal/connector/exchange/iterators_test.go b/src/internal/connector/exchange/iterators_test.go index dd5abade7..5e9902b6c 100644 --- a/src/internal/connector/exchange/iterators_test.go +++ b/src/internal/connector/exchange/iterators_test.go @@ -3,11 +3,11 @@ package exchange import ( "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/mockconnector" "github.com/alcionai/corso/src/internal/connector/support" diff --git a/src/internal/connector/exchange/mail_folder_cache.go b/src/internal/connector/exchange/mail_folder_cache.go index 4bb20c977..cb014482f 100644 --- a/src/internal/connector/exchange/mail_folder_cache.go +++ b/src/internal/connector/exchange/mail_folder_cache.go @@ -4,7 +4,6 @@ import ( "context" "github.com/alcionai/clues" - "github.com/pkg/errors" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/pkg/fault" @@ -72,16 +71,16 @@ func (mc *mailFolderCache) Populate( baseContainerPath ...string, ) error { if err := mc.init(ctx); err != nil { - return errors.Wrap(err, "initializing") + return clues.Wrap(err, "initializing") } err := mc.enumer.EnumerateContainers(ctx, mc.userID, "", mc.addFolder, errs) if err != nil { - return errors.Wrap(err, "enumerating containers") + return clues.Wrap(err, "enumerating containers") } if err := mc.populatePaths(ctx, false, errs); err != nil { - return errors.Wrap(err, "populating paths") + return clues.Wrap(err, "populating paths") } return nil diff --git a/src/internal/connector/exchange/mail_folder_cache_test.go b/src/internal/connector/exchange/mail_folder_cache_test.go index 9227fc51c..42dc407d1 100644 --- a/src/internal/connector/exchange/mail_folder_cache_test.go +++ b/src/internal/connector/exchange/mail_folder_cache_test.go @@ -4,11 +4,11 @@ import ( stdpath "path" "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/exchange/api" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/account" diff --git a/src/internal/connector/exchange/restore_test.go b/src/internal/connector/exchange/restore_test.go index cd8448c94..619720e75 100644 --- a/src/internal/connector/exchange/restore_test.go +++ b/src/internal/connector/exchange/restore_test.go @@ -5,11 +5,11 @@ import ( "testing" "time" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/exchange/api" diff --git a/src/internal/connector/exchange/service_functions.go b/src/internal/connector/exchange/service_functions.go index 62b1058ff..d19b03f52 100644 --- a/src/internal/connector/exchange/service_functions.go +++ b/src/internal/connector/exchange/service_functions.go @@ -4,7 +4,6 @@ import ( "context" "github.com/alcionai/clues" - "github.com/pkg/errors" "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/exchange/api" @@ -15,7 +14,7 @@ import ( "github.com/alcionai/corso/src/pkg/selectors" ) -var ErrFolderNotFound = errors.New("folder not found") +var ErrFolderNotFound = clues.New("folder not found") func createService(credentials account.M365Config) (*graph.Service, error) { adapter, err := graph.CreateAdapter( @@ -23,7 +22,7 @@ func createService(credentials account.M365Config) (*graph.Service, error) { credentials.AzureClientID, credentials.AzureClientSecret) if err != nil { - return nil, errors.Wrap(err, "creating microsoft graph service for exchange") + return nil, clues.Wrap(err, "creating microsoft graph service for exchange") } return graph.NewService(adapter), nil diff --git a/src/internal/connector/exchange/service_iterators.go b/src/internal/connector/exchange/service_iterators.go index 07eab2f7b..a014f0797 100644 --- a/src/internal/connector/exchange/service_iterators.go +++ b/src/internal/connector/exchange/service_iterators.go @@ -4,7 +4,6 @@ import ( "context" "github.com/alcionai/clues" - "github.com/pkg/errors" "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/exchange/api" @@ -235,7 +234,7 @@ func makeTombstones(dps DeltaPaths) map[string]string { func pathFromPrevString(ps string) (path.Path, error) { p, err := path.FromDataLayerPath(ps, false) if err != nil { - return nil, errors.Wrap(err, "parsing previous path string") + return nil, clues.Wrap(err, "parsing previous path string") } return p, nil diff --git a/src/internal/connector/exchange/service_iterators_test.go b/src/internal/connector/exchange/service_iterators_test.go index 1dd744eb5..580598bf6 100644 --- a/src/internal/connector/exchange/service_iterators_test.go +++ b/src/internal/connector/exchange/service_iterators_test.go @@ -4,12 +4,11 @@ import ( "context" "testing" - "github.com/pkg/errors" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/exchange/api" "github.com/alcionai/corso/src/internal/connector/graph" @@ -50,7 +49,7 @@ func (mg mockGetter) GetAddedAndRemovedItemIDs( ) { results, ok := mg[cID] if !ok { - return nil, nil, api.DeltaUpdate{}, errors.New("mock not found for " + cID) + return nil, nil, api.DeltaUpdate{}, clues.New("mock not found for " + cID) } return results.added, results.removed, results.newDelta, results.err diff --git a/src/internal/connector/exchange/service_restore.go b/src/internal/connector/exchange/service_restore.go index d2e778bed..d4c6774ae 100644 --- a/src/internal/connector/exchange/service_restore.go +++ b/src/internal/connector/exchange/service_restore.go @@ -9,7 +9,6 @@ import ( "github.com/alcionai/clues" "github.com/microsoftgraph/msgraph-sdk-go/models" - "github.com/pkg/errors" "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/common/ptr" @@ -283,7 +282,7 @@ func SendMailToBackStore( continue } - el.AddRecoverable(errors.Wrap(err, "uploading mail attachment")) + el.AddRecoverable(clues.Wrap(err, "uploading mail attachment")) break } @@ -622,7 +621,7 @@ func establishMailRestoreLocation( // call even if we make a new cache. if isNewCache { if err := mfc.Populate(ctx, errs, rootFolderAlias); err != nil { - return "", errors.Wrap(err, "populating folder cache") + return "", clues.Wrap(err, "populating folder cache") } isNewCache = false @@ -630,7 +629,7 @@ func establishMailRestoreLocation( // NOOP if the folder is already in the cache. if err = mfc.AddToCache(ctx, temp, false); err != nil { - return "", errors.Wrap(err, "adding folder to cache") + return "", clues.Wrap(err, "adding folder to cache") } } @@ -668,11 +667,11 @@ func establishContactsRestoreLocation( if isNewCache { if err := cfc.Populate(ctx, errs, folderID, folders[0]); err != nil { - return "", errors.Wrap(err, "populating contact cache") + return "", clues.Wrap(err, "populating contact cache") } if err = cfc.AddToCache(ctx, temp, false); err != nil { - return "", errors.Wrap(err, "adding contact folder to cache") + return "", clues.Wrap(err, "adding contact folder to cache") } } @@ -705,12 +704,12 @@ func establishEventsRestoreLocation( if isNewCache { if err = ecc.Populate(ctx, errs, folderID, folders[0]); err != nil { - return "", errors.Wrap(err, "populating event cache") + return "", clues.Wrap(err, "populating event cache") } displayable := api.CalendarDisplayable{Calendarable: temp} if err = ecc.AddToCache(ctx, displayable, true); err != nil { - return "", errors.Wrap(err, "adding new calendar to cache") + return "", clues.Wrap(err, "adding new calendar to cache") } } diff --git a/src/internal/connector/graph/cache_container.go b/src/internal/connector/graph/cache_container.go index 224b3d027..9675612cc 100644 --- a/src/internal/connector/graph/cache_container.go +++ b/src/internal/connector/graph/cache_container.go @@ -5,7 +5,6 @@ import ( "github.com/alcionai/clues" "github.com/microsoftgraph/msgraph-sdk-go/models" - "github.com/pkg/errors" "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/pkg/fault" @@ -175,7 +174,7 @@ func CreateCalendarDisplayable(entry any, parentID string) *CalendarDisplayable func CheckRequiredValues(c Container) error { id, ok := ptr.ValOK(c.GetId()) if !ok { - return errors.New("container missing ID") + return clues.New("container missing ID") } if _, ok := ptr.ValOK(c.GetDisplayName()); !ok { diff --git a/src/internal/connector/graph/errors.go b/src/internal/connector/graph/errors.go index f45aeb1b7..5148e4dda 100644 --- a/src/internal/connector/graph/errors.go +++ b/src/internal/connector/graph/errors.go @@ -9,12 +9,12 @@ import ( "os" "strings" + "github.com/alcionai/clues" "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/microsoftgraph/msgraph-sdk-go/models/odataerrors" "github.com/pkg/errors" "golang.org/x/exp/slices" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/pkg/fault" "github.com/alcionai/corso/src/pkg/logger" diff --git a/src/internal/connector/graph/errors_test.go b/src/internal/connector/graph/errors_test.go index 0fb5575c6..0ba535ce9 100644 --- a/src/internal/connector/graph/errors_test.go +++ b/src/internal/connector/graph/errors_test.go @@ -5,12 +5,12 @@ import ( "net/http" "testing" + "github.com/alcionai/clues" "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/microsoftgraph/msgraph-sdk-go/models/odataerrors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/fault" ) diff --git a/src/internal/connector/graph/metadata/metadata_test.go b/src/internal/connector/graph/metadata/metadata_test.go index 6c598f423..41637b39e 100644 --- a/src/internal/connector/graph/metadata/metadata_test.go +++ b/src/internal/connector/graph/metadata/metadata_test.go @@ -4,11 +4,11 @@ import ( "fmt" "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/graph/metadata" "github.com/alcionai/corso/src/internal/connector/onedrive" "github.com/alcionai/corso/src/internal/tester" diff --git a/src/internal/connector/graph/metadata_collection.go b/src/internal/connector/graph/metadata_collection.go index a5a945389..357f6bc7d 100644 --- a/src/internal/connector/graph/metadata_collection.go +++ b/src/internal/connector/graph/metadata_collection.go @@ -6,7 +6,7 @@ import ( "encoding/json" "io" - "github.com/pkg/errors" + "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/support" "github.com/alcionai/corso/src/internal/data" @@ -42,18 +42,18 @@ func NewMetadataEntry(fileName string, mData any) MetadataCollectionEntry { func (mce MetadataCollectionEntry) toMetadataItem() (MetadataItem, error) { if len(mce.fileName) == 0 { - return MetadataItem{}, errors.New("missing metadata filename") + return MetadataItem{}, clues.New("missing metadata filename") } if mce.data == nil { - return MetadataItem{}, errors.New("missing metadata") + return MetadataItem{}, clues.New("missing metadata") } buf := &bytes.Buffer{} encoder := json.NewEncoder(buf) if err := encoder.Encode(mce.data); err != nil { - return MetadataItem{}, errors.Wrap(err, "serializing metadata") + return MetadataItem{}, clues.Wrap(err, "serializing metadata") } return NewMetadataItem(mce.fileName, buf.Bytes()), nil @@ -81,7 +81,7 @@ func MakeMetadataCollection( false, ) if err != nil { - return nil, errors.Wrap(err, "making metadata path") + return nil, clues.Wrap(err, "making metadata path") } items := make([]MetadataItem, 0, len(metadata)) diff --git a/src/internal/connector/graph/metadata_collection_test.go b/src/internal/connector/graph/metadata_collection_test.go index 02104ab20..6b35b1453 100644 --- a/src/internal/connector/graph/metadata_collection_test.go +++ b/src/internal/connector/graph/metadata_collection_test.go @@ -5,12 +5,12 @@ import ( "io" "testing" + "github.com/alcionai/clues" "github.com/google/uuid" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/support" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/fault" diff --git a/src/internal/connector/graph/service.go b/src/internal/connector/graph/service.go index 8db4670f8..890e8caef 100644 --- a/src/internal/connector/graph/service.go +++ b/src/internal/connector/graph/service.go @@ -10,16 +10,15 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/alcionai/clues" backoff "github.com/cenkalti/backoff/v4" "github.com/microsoft/kiota-abstractions-go/serialization" ka "github.com/microsoft/kiota-authentication-azure-go" khttp "github.com/microsoft/kiota-http-go" msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go" msgraphgocore "github.com/microsoftgraph/msgraph-sdk-go-core" - "github.com/pkg/errors" "golang.org/x/time/rate" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/logger" "github.com/alcionai/corso/src/pkg/path" @@ -81,12 +80,12 @@ func (s Service) Client() *msgraphsdk.GraphServiceClient { func (s Service) Serialize(object serialization.Parsable) ([]byte, error) { writer, err := s.adapter.GetSerializationWriterFactory().GetSerializationWriter("application/json") if err != nil || writer == nil { - return nil, errors.Wrap(err, "creating json serialization writer") + return nil, clues.Wrap(err, "creating json serialization writer") } err = writer.WriteObjectValue("", object) if err != nil { - return nil, errors.Wrap(err, "serializing object") + return nil, clues.Wrap(err, "serializing object") } return writer.GetSerializedContent() @@ -175,7 +174,7 @@ func CreateAdapter( // Client Provider: Uses Secret for access to tenant-level data cred, err := azidentity.NewClientSecretCredential(tenant, client, secret, nil) if err != nil { - return nil, errors.Wrap(err, "creating m365 client identity") + return nil, clues.Wrap(err, "creating m365 client identity") } auth, err := ka.NewAzureIdentityAuthenticationProviderWithScopes( @@ -183,7 +182,7 @@ func CreateAdapter( []string{"https://graph.microsoft.com/.default"}, ) if err != nil { - return nil, errors.Wrap(err, "creating azure authentication") + return nil, clues.Wrap(err, "creating azure authentication") } httpClient := HTTPClient(opts...) diff --git a/src/internal/connector/graph/service_test.go b/src/internal/connector/graph/service_test.go index 498a6cc93..d4dbdec59 100644 --- a/src/internal/connector/graph/service_test.go +++ b/src/internal/connector/graph/service_test.go @@ -5,12 +5,12 @@ import ( "testing" "time" + "github.com/alcionai/clues" "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/account" ) diff --git a/src/internal/connector/graph_connector.go b/src/internal/connector/graph_connector.go index d20d0fabd..ef004e77d 100644 --- a/src/internal/connector/graph_connector.go +++ b/src/internal/connector/graph_connector.go @@ -93,7 +93,7 @@ func NewGraphConnector( if r == AllResources || r == Sites { if err = gc.setTenantSites(ctx, errs); err != nil { - return nil, errors.Wrap(err, "retrieveing tenant site list") + return nil, clues.Wrap(err, "retrieveing tenant site list") } } @@ -139,7 +139,7 @@ func (gc *GraphConnector) setTenantSites(ctx context.Context, errs *fault.Bus) e return nil } -var errKnownSkippableCase = errors.New("case is known and skippable") +var errKnownSkippableCase = clues.New("case is known and skippable") const personalSitePath = "sharepoint.com/personal/" diff --git a/src/internal/connector/graph_connector_disconnected_test.go b/src/internal/connector/graph_connector_disconnected_test.go index c4d1d1e56..0d4c6ca30 100644 --- a/src/internal/connector/graph_connector_disconnected_test.go +++ b/src/internal/connector/graph_connector_disconnected_test.go @@ -4,11 +4,11 @@ import ( "sync" "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/support" "github.com/alcionai/corso/src/internal/tester" diff --git a/src/internal/connector/graph_connector_helper_test.go b/src/internal/connector/graph_connector_helper_test.go index 76f90bdb8..8b7680083 100644 --- a/src/internal/connector/graph_connector_helper_test.go +++ b/src/internal/connector/graph_connector_helper_test.go @@ -10,13 +10,13 @@ import ( "strings" "testing" + "github.com/alcionai/clues" "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "golang.org/x/exp/maps" "golang.org/x/exp/slices" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/mockconnector" "github.com/alcionai/corso/src/internal/connector/onedrive" diff --git a/src/internal/connector/graph_connector_onedrive_test.go b/src/internal/connector/graph_connector_onedrive_test.go index 7e505f96e..385055860 100644 --- a/src/internal/connector/graph_connector_onedrive_test.go +++ b/src/internal/connector/graph_connector_onedrive_test.go @@ -8,12 +8,12 @@ import ( "strings" "testing" + "github.com/alcionai/clues" "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/onedrive" diff --git a/src/internal/connector/graph_connector_test.go b/src/internal/connector/graph_connector_test.go index a8842c0c5..2ee84257c 100644 --- a/src/internal/connector/graph_connector_test.go +++ b/src/internal/connector/graph_connector_test.go @@ -5,12 +5,12 @@ import ( "testing" "time" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" "golang.org/x/exp/maps" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/mockconnector" "github.com/alcionai/corso/src/internal/data" diff --git a/src/internal/connector/mockconnector/mock_data_collection_test.go b/src/internal/connector/mockconnector/mock_data_collection_test.go index d0682bdaa..7b4919ce8 100644 --- a/src/internal/connector/mockconnector/mock_data_collection_test.go +++ b/src/internal/connector/mockconnector/mock_data_collection_test.go @@ -5,13 +5,13 @@ import ( "io" "testing" + "github.com/alcionai/clues" kioser "github.com/microsoft/kiota-serialization-json-go" "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/mockconnector" "github.com/alcionai/corso/src/internal/connector/support" "github.com/alcionai/corso/src/internal/data" diff --git a/src/internal/connector/mockconnector/mock_data_list.go b/src/internal/connector/mockconnector/mock_data_list.go index 288a6c7b6..d08c2376d 100644 --- a/src/internal/connector/mockconnector/mock_data_list.go +++ b/src/internal/connector/mockconnector/mock_data_list.go @@ -6,11 +6,11 @@ import ( "io" "testing" + "github.com/alcionai/clues" kw "github.com/microsoft/kiota-serialization-json-go" "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/stretchr/testify/require" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/data" "github.com/alcionai/corso/src/pkg/fault" "github.com/alcionai/corso/src/pkg/path" diff --git a/src/internal/connector/mockconnector/mock_data_message.go b/src/internal/connector/mockconnector/mock_data_message.go index 86e602f7b..32355a03a 100644 --- a/src/internal/connector/mockconnector/mock_data_message.go +++ b/src/internal/connector/mockconnector/mock_data_message.go @@ -5,13 +5,12 @@ import ( "fmt" "testing" + "github.com/alcionai/clues" absser "github.com/microsoft/kiota-abstractions-go/serialization" js "github.com/microsoft/kiota-serialization-json-go" "github.com/microsoftgraph/msgraph-sdk-go/models" - "github.com/pkg/errors" "github.com/stretchr/testify/require" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common" ) @@ -748,12 +747,12 @@ func serialize(t *testing.T, item absser.Parsable) []byte { func hydrateMessage(byteArray []byte) (models.Messageable, error) { parseNode, err := js.NewJsonParseNodeFactory().GetRootParseNode("application/json", byteArray) if err != nil { - return nil, errors.Wrap(err, "deserializing bytes into base m365 object") + return nil, clues.Wrap(err, "deserializing bytes into base m365 object") } anObject, err := parseNode.GetObjectValue(models.CreateMessageFromDiscriminatorValue) if err != nil { - return nil, errors.Wrap(err, "parsing m365 object factory") + return nil, clues.Wrap(err, "parsing m365 object factory") } message := anObject.(models.Messageable) diff --git a/src/internal/connector/onedrive/api/drive_test.go b/src/internal/connector/onedrive/api/drive_test.go index 853dba63a..26d189d9d 100644 --- a/src/internal/connector/onedrive/api/drive_test.go +++ b/src/internal/connector/onedrive/api/drive_test.go @@ -3,11 +3,11 @@ package api_test import ( "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/onedrive/api" "github.com/alcionai/corso/src/internal/tester" diff --git a/src/internal/connector/onedrive/collection.go b/src/internal/connector/onedrive/collection.go index 5cc6c34ad..5ac7a14dd 100644 --- a/src/internal/connector/onedrive/collection.go +++ b/src/internal/connector/onedrive/collection.go @@ -12,7 +12,6 @@ import ( "github.com/alcionai/clues" "github.com/microsoftgraph/msgraph-sdk-go/models" - "github.com/pkg/errors" "github.com/spatialcurrent/go-lazy/pkg/lazy" "github.com/alcionai/corso/src/internal/common/ptr" @@ -329,7 +328,7 @@ func (oc *Collection) getDriveItemContent( // refresh that download url. di, diErr := oc.itemGetter(ctx, oc.service, oc.driveID, itemID) if diErr != nil { - err = errors.Wrap(diErr, "retrieving expired item") + err = clues.Wrap(diErr, "retrieving expired item") break } diff --git a/src/internal/connector/onedrive/collection_test.go b/src/internal/connector/onedrive/collection_test.go index 1d4fe5dd1..dbf5d76a3 100644 --- a/src/internal/connector/onedrive/collection_test.go +++ b/src/internal/connector/onedrive/collection_test.go @@ -11,13 +11,13 @@ import ( "testing" "time" + "github.com/alcionai/clues" msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go" "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/support" "github.com/alcionai/corso/src/internal/data" diff --git a/src/internal/connector/onedrive/collections.go b/src/internal/connector/onedrive/collections.go index 1113020c5..acab9e573 100644 --- a/src/internal/connector/onedrive/collections.go +++ b/src/internal/connector/onedrive/collections.go @@ -231,7 +231,7 @@ func deserializeMap[T any](reader io.ReadCloser, alreadyFound map[string]T) erro tmp := map[string]T{} if err := json.NewDecoder(reader).Decode(&tmp); err != nil { - return errors.Wrap(err, "deserializing file contents") + return clues.Wrap(err, "deserializing file contents") } var duplicate bool @@ -853,7 +853,7 @@ func GetCanonicalPath(p, tenant, resourceOwner string, source driveSource) (path } if err != nil { - return nil, errors.Wrap(err, "converting to canonical path") + return nil, clues.Wrap(err, "converting to canonical path") } return result, nil diff --git a/src/internal/connector/onedrive/collections_test.go b/src/internal/connector/onedrive/collections_test.go index ee2ca35d8..ffe42f777 100644 --- a/src/internal/connector/onedrive/collections_test.go +++ b/src/internal/connector/onedrive/collections_test.go @@ -6,6 +6,7 @@ import ( "strings" "testing" + "github.com/alcionai/clues" "github.com/google/uuid" "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/microsoftgraph/msgraph-sdk-go/models/odataerrors" @@ -14,7 +15,6 @@ import ( "github.com/stretchr/testify/suite" "golang.org/x/exp/maps" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/graph" gapi "github.com/alcionai/corso/src/internal/connector/graph/api" "github.com/alcionai/corso/src/internal/connector/onedrive/api" diff --git a/src/internal/connector/onedrive/data_collections.go b/src/internal/connector/onedrive/data_collections.go index 8da845503..fbad7fc4b 100644 --- a/src/internal/connector/onedrive/data_collections.go +++ b/src/internal/connector/onedrive/data_collections.go @@ -5,6 +5,8 @@ import ( "net/http" "github.com/alcionai/clues" + "golang.org/x/exp/maps" + "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/support" "github.com/alcionai/corso/src/internal/data" @@ -13,7 +15,6 @@ import ( "github.com/alcionai/corso/src/pkg/logger" "github.com/alcionai/corso/src/pkg/path" "github.com/alcionai/corso/src/pkg/selectors" - "golang.org/x/exp/maps" ) type odFolderMatcher struct { diff --git a/src/internal/connector/onedrive/drive.go b/src/internal/connector/onedrive/drive.go index 6ec63f7d4..1f414cd12 100644 --- a/src/internal/connector/onedrive/drive.go +++ b/src/internal/connector/onedrive/drive.go @@ -8,7 +8,6 @@ import ( "github.com/alcionai/clues" msdrive "github.com/microsoftgraph/msgraph-sdk-go/drive" "github.com/microsoftgraph/msgraph-sdk-go/models" - "github.com/pkg/errors" "golang.org/x/exp/maps" "github.com/alcionai/corso/src/internal/common/ptr" @@ -55,7 +54,7 @@ func PagerForSource( case SharePointSource: return api.NewSiteDrivePager(servicer, resourceOwner, fields), nil default: - return nil, errors.Errorf("unrecognized drive data source") + return nil, clues.New("unrecognized drive data source") } } @@ -286,7 +285,7 @@ func GetAllFolders( ) ([]*Displayable, error) { drives, err := api.GetAllDrives(ctx, pager, true, maxDrivesRetries) if err != nil { - return nil, errors.Wrap(err, "getting OneDrive folders") + return nil, clues.Wrap(err, "getting OneDrive folders") } var ( diff --git a/src/internal/connector/onedrive/item.go b/src/internal/connector/onedrive/item.go index 59f10c3f8..d7d040151 100644 --- a/src/internal/connector/onedrive/item.go +++ b/src/internal/connector/onedrive/item.go @@ -11,7 +11,6 @@ import ( "github.com/alcionai/clues" msdrives "github.com/microsoftgraph/msgraph-sdk-go/drives" "github.com/microsoftgraph/msgraph-sdk-go/models" - "github.com/pkg/errors" "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/graph" @@ -52,7 +51,7 @@ func sharePointItemReader( ) (details.ItemInfo, io.ReadCloser, error) { resp, err := downloadItem(ctx, hc, item) if err != nil { - return details.ItemInfo{}, nil, errors.Wrap(err, "downloading item") + return details.ItemInfo{}, nil, clues.Wrap(err, "downloading item") } dii := details.ItemInfo{ @@ -135,7 +134,7 @@ func oneDriveItemReader( if isFile { resp, err := downloadItem(ctx, hc, item) if err != nil { - return details.ItemInfo{}, nil, errors.Wrap(err, "downloading item") + return details.ItemInfo{}, nil, clues.Wrap(err, "downloading item") } rc = resp.Body diff --git a/src/internal/connector/onedrive/item_test.go b/src/internal/connector/onedrive/item_test.go index ef562fbd6..89dbd4036 100644 --- a/src/internal/connector/onedrive/item_test.go +++ b/src/internal/connector/onedrive/item_test.go @@ -6,12 +6,12 @@ import ( "io" "testing" + "github.com/alcionai/clues" "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/graph" diff --git a/src/internal/connector/onedrive/permission.go b/src/internal/connector/onedrive/permission.go index b618d59b4..b0c198302 100644 --- a/src/internal/connector/onedrive/permission.go +++ b/src/internal/connector/onedrive/permission.go @@ -6,7 +6,6 @@ import ( "github.com/alcionai/clues" msdrive "github.com/microsoftgraph/msgraph-sdk-go/drive" "github.com/microsoftgraph/msgraph-sdk-go/models" - "github.com/pkg/errors" "golang.org/x/exp/slices" "github.com/alcionai/corso/src/internal/common/ptr" @@ -24,11 +23,11 @@ func getParentMetadata( if !ok { onedrivePath, err := path.ToOneDrivePath(parentPath) if err != nil { - return Metadata{}, errors.Wrap(err, "invalid restore path") + return Metadata{}, clues.Wrap(err, "invalid restore path") } if len(onedrivePath.Folders) != 0 { - return Metadata{}, errors.Wrap(err, "computing item permissions") + return Metadata{}, clues.Wrap(err, "computing item permissions") } parentMeta = Metadata{} diff --git a/src/internal/connector/onedrive/restore_test.go b/src/internal/connector/onedrive/restore_test.go index 26ad369c3..f0ecb7580 100644 --- a/src/internal/connector/onedrive/restore_test.go +++ b/src/internal/connector/onedrive/restore_test.go @@ -4,12 +4,13 @@ import ( "testing" "github.com/alcionai/clues" - "github.com/alcionai/corso/src/internal/tester" - "github.com/alcionai/corso/src/internal/version" - "github.com/alcionai/corso/src/pkg/path" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + + "github.com/alcionai/corso/src/internal/tester" + "github.com/alcionai/corso/src/internal/version" + "github.com/alcionai/corso/src/pkg/path" ) type RestoreUnitSuite struct { diff --git a/src/internal/connector/onedrive/service_test.go b/src/internal/connector/onedrive/service_test.go index d2bffa258..94aac53b3 100644 --- a/src/internal/connector/onedrive/service_test.go +++ b/src/internal/connector/onedrive/service_test.go @@ -3,10 +3,10 @@ package onedrive import ( "testing" + "github.com/alcionai/clues" msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go" "github.com/stretchr/testify/require" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/support" "github.com/alcionai/corso/src/internal/tester" diff --git a/src/internal/connector/sharepoint/api/helper_test.go b/src/internal/connector/sharepoint/api/helper_test.go index 974d3cc43..e1982a178 100644 --- a/src/internal/connector/sharepoint/api/helper_test.go +++ b/src/internal/connector/sharepoint/api/helper_test.go @@ -3,9 +3,9 @@ package api_test import ( "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/require" - "github.com/alcionai/clues" discover "github.com/alcionai/corso/src/internal/connector/discovery/api" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/pkg/account" diff --git a/src/internal/connector/sharepoint/api/pages.go b/src/internal/connector/sharepoint/api/pages.go index a06a25ad8..d21a81fe7 100644 --- a/src/internal/connector/sharepoint/api/pages.go +++ b/src/internal/connector/sharepoint/api/pages.go @@ -6,9 +6,10 @@ import ( "io" "sync" - "github.com/pkg/errors" - "github.com/alcionai/clues" + msmodels "github.com/microsoftgraph/msgraph-sdk-go/models" + mssites "github.com/microsoftgraph/msgraph-sdk-go/sites" + "github.com/alcionai/corso/src/internal/common/ptr" discover "github.com/alcionai/corso/src/internal/connector/discovery/api" "github.com/alcionai/corso/src/internal/connector/graph" @@ -19,8 +20,6 @@ import ( D "github.com/alcionai/corso/src/internal/diagnostics" "github.com/alcionai/corso/src/pkg/backup/details" "github.com/alcionai/corso/src/pkg/fault" - msmodels "github.com/microsoftgraph/msgraph-sdk-go/models" - mssites "github.com/microsoftgraph/msgraph-sdk-go/sites" ) // GetSitePages retrieves a collection of Pages related to the give Site. @@ -206,7 +205,7 @@ func RestoreSitePage( // Hydrate Page page, err := support.CreatePageFromBytes(byteArray) if err != nil { - return dii, errors.Wrapf(err, "creating Page object %s", pageID) + return dii, clues.Wrap(err, "creating Page object").WithClues(ctx) } name, ok := ptr.ValOK(page.GetName()) diff --git a/src/internal/connector/sharepoint/api/pages_test.go b/src/internal/connector/sharepoint/api/pages_test.go index 36db24bc1..a10b7525a 100644 --- a/src/internal/connector/sharepoint/api/pages_test.go +++ b/src/internal/connector/sharepoint/api/pages_test.go @@ -5,11 +5,11 @@ import ( "io" "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common" discover "github.com/alcionai/corso/src/internal/connector/discovery/api" "github.com/alcionai/corso/src/internal/connector/mockconnector" diff --git a/src/internal/connector/sharepoint/collection_test.go b/src/internal/connector/sharepoint/collection_test.go index ae962df0c..e32528582 100644 --- a/src/internal/connector/sharepoint/collection_test.go +++ b/src/internal/connector/sharepoint/collection_test.go @@ -5,13 +5,13 @@ import ( "io" "testing" + "github.com/alcionai/clues" kioser "github.com/microsoft/kiota-serialization-json-go" "github.com/microsoftgraph/msgraph-sdk-go/sites" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/mockconnector" diff --git a/src/internal/connector/sharepoint/data_collections.go b/src/internal/connector/sharepoint/data_collections.go index bc72f9e57..686f3f223 100644 --- a/src/internal/connector/sharepoint/data_collections.go +++ b/src/internal/connector/sharepoint/data_collections.go @@ -4,9 +4,8 @@ import ( "context" "net/http" - "github.com/pkg/errors" - "github.com/alcionai/clues" + "github.com/alcionai/corso/src/internal/connector/discovery/api" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/onedrive" @@ -40,7 +39,7 @@ func DataCollections( ) ([]data.BackupCollection, map[string]map[string]struct{}, error) { b, err := selector.ToSharePointBackup() if err != nil { - return nil, nil, errors.Wrap(err, "sharePointDataCollection: parsing selector") + return nil, nil, clues.Wrap(err, "sharePointDataCollection: parsing selector") } var ( diff --git a/src/internal/connector/sharepoint/data_collections_test.go b/src/internal/connector/sharepoint/data_collections_test.go index 558c8583d..b7411e059 100644 --- a/src/internal/connector/sharepoint/data_collections_test.go +++ b/src/internal/connector/sharepoint/data_collections_test.go @@ -3,12 +3,12 @@ package sharepoint import ( "testing" + "github.com/alcionai/clues" "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/onedrive" "github.com/alcionai/corso/src/internal/tester" diff --git a/src/internal/connector/sharepoint/helper_test.go b/src/internal/connector/sharepoint/helper_test.go index 6b1e8eaa5..d306e212a 100644 --- a/src/internal/connector/sharepoint/helper_test.go +++ b/src/internal/connector/sharepoint/helper_test.go @@ -3,10 +3,10 @@ package sharepoint import ( "testing" + "github.com/alcionai/clues" msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go" "github.com/stretchr/testify/require" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/onedrive" "github.com/alcionai/corso/src/internal/connector/support" diff --git a/src/internal/connector/sharepoint/list_test.go b/src/internal/connector/sharepoint/list_test.go index dd866b5cf..7d66b652e 100644 --- a/src/internal/connector/sharepoint/list_test.go +++ b/src/internal/connector/sharepoint/list_test.go @@ -3,11 +3,11 @@ package sharepoint import ( "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/fault" diff --git a/src/internal/connector/support/m365Support.go b/src/internal/connector/support/m365Support.go index aff494dad..b44b9b45d 100644 --- a/src/internal/connector/support/m365Support.go +++ b/src/internal/connector/support/m365Support.go @@ -1,10 +1,10 @@ package support import ( + "github.com/alcionai/clues" absser "github.com/microsoft/kiota-abstractions-go/serialization" js "github.com/microsoft/kiota-serialization-json-go" "github.com/microsoftgraph/msgraph-sdk-go/models" - "github.com/pkg/errors" bmodels "github.com/alcionai/corso/src/internal/connector/graph/betasdk/models" ) @@ -14,12 +14,12 @@ import ( func CreateFromBytes(bytes []byte, createFunc absser.ParsableFactory) (absser.Parsable, error) { parseNode, err := js.NewJsonParseNodeFactory().GetRootParseNode("application/json", bytes) if err != nil { - return nil, errors.Wrap(err, "deserializing bytes into base m365 object") + return nil, clues.Wrap(err, "deserializing bytes into base m365 object") } anObject, err := parseNode.GetObjectValue(createFunc) if err != nil { - return nil, errors.Wrap(err, "parsing m365 object factory") + return nil, clues.Wrap(err, "parsing m365 object factory") } return anObject, nil @@ -29,7 +29,7 @@ func CreateFromBytes(bytes []byte, createFunc absser.ParsableFactory) (absser.Pa func CreateMessageFromBytes(bytes []byte) (models.Messageable, error) { aMessage, err := CreateFromBytes(bytes, models.CreateMessageFromDiscriminatorValue) if err != nil { - return nil, errors.Wrap(err, "deserializing bytes to exchange message") + return nil, clues.Wrap(err, "deserializing bytes to exchange message") } message := aMessage.(models.Messageable) @@ -42,7 +42,7 @@ func CreateMessageFromBytes(bytes []byte) (models.Messageable, error) { func CreateContactFromBytes(bytes []byte) (models.Contactable, error) { parsable, err := CreateFromBytes(bytes, models.CreateContactFromDiscriminatorValue) if err != nil { - return nil, errors.Wrap(err, "deserializing bytes to exchange contact") + return nil, clues.Wrap(err, "deserializing bytes to exchange contact") } contact := parsable.(models.Contactable) @@ -54,7 +54,7 @@ func CreateContactFromBytes(bytes []byte) (models.Contactable, error) { func CreateEventFromBytes(bytes []byte) (models.Eventable, error) { parsable, err := CreateFromBytes(bytes, models.CreateEventFromDiscriminatorValue) if err != nil { - return nil, errors.Wrap(err, "deserializing bytes to exchange event") + return nil, clues.Wrap(err, "deserializing bytes to exchange event") } event := parsable.(models.Eventable) @@ -66,7 +66,7 @@ func CreateEventFromBytes(bytes []byte) (models.Eventable, error) { func CreateListFromBytes(bytes []byte) (models.Listable, error) { parsable, err := CreateFromBytes(bytes, models.CreateListFromDiscriminatorValue) if err != nil { - return nil, errors.Wrap(err, "deserializing bytes to sharepoint list") + return nil, clues.Wrap(err, "deserializing bytes to sharepoint list") } list := parsable.(models.Listable) @@ -78,7 +78,7 @@ func CreateListFromBytes(bytes []byte) (models.Listable, error) { func CreatePageFromBytes(bytes []byte) (bmodels.SitePageable, error) { parsable, err := CreateFromBytes(bytes, bmodels.CreateSitePageFromDiscriminatorValue) if err != nil { - return nil, errors.Wrap(err, "deserializing bytes to sharepoint page") + return nil, clues.Wrap(err, "deserializing bytes to sharepoint page") } page := parsable.(bmodels.SitePageable) diff --git a/src/internal/connector/support/m365Support_test.go b/src/internal/connector/support/m365Support_test.go index d8e352c71..59aee91dc 100644 --- a/src/internal/connector/support/m365Support_test.go +++ b/src/internal/connector/support/m365Support_test.go @@ -3,12 +3,12 @@ package support import ( "testing" + "github.com/alcionai/clues" kioser "github.com/microsoft/kiota-serialization-json-go" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" bmodels "github.com/alcionai/corso/src/internal/connector/graph/betasdk/models" "github.com/alcionai/corso/src/internal/connector/mockconnector" "github.com/alcionai/corso/src/internal/tester" diff --git a/src/internal/connector/support/m365Transform_test.go b/src/internal/connector/support/m365Transform_test.go index 97ac02b12..355959843 100644 --- a/src/internal/connector/support/m365Transform_test.go +++ b/src/internal/connector/support/m365Transform_test.go @@ -3,12 +3,12 @@ package support import ( "testing" + "github.com/alcionai/clues" "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/mockconnector" "github.com/alcionai/corso/src/internal/tester" diff --git a/src/internal/connector/uploadsession/uploadsession_test.go b/src/internal/connector/uploadsession/uploadsession_test.go index c10c75e8d..9fdf88b5d 100644 --- a/src/internal/connector/uploadsession/uploadsession_test.go +++ b/src/internal/connector/uploadsession/uploadsession_test.go @@ -10,11 +10,11 @@ import ( "strconv" "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/tester" ) diff --git a/src/internal/data/data_collection.go b/src/internal/data/data_collection.go index ff11d4e1a..23f402083 100644 --- a/src/internal/data/data_collection.go +++ b/src/internal/data/data_collection.go @@ -2,10 +2,11 @@ package data import ( "context" - "errors" "io" "time" + "github.com/alcionai/clues" + "github.com/alcionai/corso/src/pkg/backup/details" "github.com/alcionai/corso/src/pkg/fault" "github.com/alcionai/corso/src/pkg/path" @@ -15,7 +16,7 @@ import ( // standard ifaces // ------------------------------------------------------------------------------------------------ -var ErrNotFound = errors.New("not found") +var ErrNotFound = clues.New("not found") type CollectionState int diff --git a/src/internal/data/data_collection_test.go b/src/internal/data/data_collection_test.go index a4f74e509..5e7f8b175 100644 --- a/src/internal/data/data_collection_test.go +++ b/src/internal/data/data_collection_test.go @@ -3,11 +3,11 @@ package data import ( "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/path" ) diff --git a/src/internal/diagnostics/diagnostics.go b/src/internal/diagnostics/diagnostics.go index 462986135..060e491ab 100644 --- a/src/internal/diagnostics/diagnostics.go +++ b/src/internal/diagnostics/diagnostics.go @@ -6,9 +6,9 @@ import ( "runtime/trace" "strings" + "github.com/alcionai/clues" "github.com/aws/aws-xray-sdk-go/xray" "github.com/aws/aws-xray-sdk-go/xraylog" - "github.com/pkg/errors" "github.com/alcionai/corso/src/pkg/logger" ) @@ -33,7 +33,7 @@ func InitCollector() error { } if err := xray.Configure(cfg); err != nil { - return errors.Wrap(err, "initializing observability tooling") + return clues.Wrap(err, "initializing observability tooling") } // TODO: feed in the corso logger diff --git a/src/internal/events/events_test.go b/src/internal/events/events_test.go index 565a98f2c..46363a695 100644 --- a/src/internal/events/events_test.go +++ b/src/internal/events/events_test.go @@ -3,10 +3,10 @@ package events_test import ( "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/events" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/account" diff --git a/src/internal/events/mock/mock.go b/src/internal/events/mock/mock.go index 0c72748a7..f7e6d0e57 100644 --- a/src/internal/events/mock/mock.go +++ b/src/internal/events/mock/mock.go @@ -3,7 +3,7 @@ package mock import ( "context" - "github.com/pkg/errors" + "github.com/alcionai/clues" ) type Bus struct { @@ -35,7 +35,7 @@ func (b *Bus) Close() error { b.TimesClosed++ if b.TimesClosed > 1 { - return errors.New("multiple closes on Bus") + return clues.New("multiple closes on Bus") } return nil diff --git a/src/internal/kopia/conn.go b/src/internal/kopia/conn.go index daf4bd681..e4d25b508 100644 --- a/src/internal/kopia/conn.go +++ b/src/internal/kopia/conn.go @@ -30,8 +30,8 @@ const ( ) var ( - ErrSettingDefaultConfig = errors.New("setting default repo config values") - ErrorRepoAlreadyExists = errors.New("repo already exists") + ErrSettingDefaultConfig = clues.New("setting default repo config values") + ErrorRepoAlreadyExists = clues.New("repo already exists") ) // Having all fields set to 0 causes it to keep max-int versions of snapshots. @@ -72,7 +72,7 @@ func NewConn(s storage.Storage) *conn { func (w *conn) Initialize(ctx context.Context) error { bst, err := blobStoreByProvider(ctx, w.storage) if err != nil { - return errors.Wrap(err, "initializing storage") + return clues.Wrap(err, "initializing storage") } defer bst.Close(ctx) @@ -111,7 +111,7 @@ func (w *conn) Initialize(ctx context.Context) error { func (w *conn) Connect(ctx context.Context) error { bst, err := blobStoreByProvider(ctx, w.storage) if err != nil { - return errors.Wrap(err, "initializing storage") + return clues.Wrap(err, "initializing storage") } defer bst.Close(ctx) diff --git a/src/internal/kopia/conn_test.go b/src/internal/kopia/conn_test.go index 553215f37..16d2bd943 100644 --- a/src/internal/kopia/conn_test.go +++ b/src/internal/kopia/conn_test.go @@ -6,13 +6,13 @@ import ( "testing" "time" + "github.com/alcionai/clues" "github.com/kopia/kopia/snapshot" "github.com/kopia/kopia/snapshot/policy" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/storage" ) diff --git a/src/internal/kopia/data_collection_test.go b/src/internal/kopia/data_collection_test.go index ae0361776..bd37738ae 100644 --- a/src/internal/kopia/data_collection_test.go +++ b/src/internal/kopia/data_collection_test.go @@ -3,17 +3,16 @@ package kopia import ( "bytes" "context" - "errors" "io" "testing" + "github.com/alcionai/clues" "github.com/kopia/kopia/fs" "github.com/kopia/kopia/fs/virtualfs" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/mockconnector" "github.com/alcionai/corso/src/internal/data" "github.com/alcionai/corso/src/internal/tester" @@ -133,7 +132,7 @@ func (suite *KopiaDataCollectionUnitSuite) TestReturnsStreams() { type mockSeeker struct{} func (s mockSeeker) Seek(offset int64, whence int) (int64, error) { - return 0, errors.New("not implemented") + return 0, clues.New("not implemented") } type mockReader struct { @@ -142,7 +141,7 @@ type mockReader struct { } func (r mockReader) Entry() (fs.Entry, error) { - return nil, errors.New("not implemented") + return nil, clues.New("not implemented") } type mockFile struct { diff --git a/src/internal/kopia/model_store.go b/src/internal/kopia/model_store.go index 90ecda844..e129aec42 100644 --- a/src/internal/kopia/model_store.go +++ b/src/internal/kopia/model_store.go @@ -22,16 +22,16 @@ const ( ) var ( - errNoModelStoreID = errors.New("model has no ModelStoreID") - errNoStableID = errors.New("model has no StableID") - errBadTagKey = errors.New("tag key overlaps with required key") - errModelTypeMismatch = errors.New("model type doesn't match request") - errUnrecognizedSchema = errors.New("unrecognized model schema") + errNoModelStoreID = clues.New("model has no ModelStoreID") + errNoStableID = clues.New("model has no StableID") + errBadTagKey = clues.New("tag key overlaps with required key") + errModelTypeMismatch = clues.New("model type doesn't match request") + errUnrecognizedSchema = clues.New("unrecognized model schema") ) func NewModelStore(c *conn) (*ModelStore, error) { if err := c.wrap(); err != nil { - return nil, errors.Wrap(err, "creating ModelStore") + return nil, clues.Wrap(err, "creating ModelStore") } return &ModelStore{c: c, modelVersion: globalModelVersion}, nil @@ -52,7 +52,11 @@ func (ms *ModelStore) Close(ctx context.Context) error { err := ms.c.Close(ctx) ms.c = nil - return errors.Wrap(err, "closing ModelStore") + if err != nil { + return clues.Wrap(err, "closing ModelStore") + } + + return nil } // tagsForModel creates a copy of tags and adds a tag for the model schema to it. @@ -192,7 +196,7 @@ func (ms ModelStore) populateBaseModelFromMetadata( v, err := strconv.Atoi(m.Labels[modelVersionKey]) if err != nil { - return errors.Wrap(err, "parsing model version") + return clues.Wrap(err, "parsing model version") } if v != ms.modelVersion { diff --git a/src/internal/kopia/model_store_test.go b/src/internal/kopia/model_store_test.go index a054a8d05..e9220f0bb 100644 --- a/src/internal/kopia/model_store_test.go +++ b/src/internal/kopia/model_store_test.go @@ -5,6 +5,7 @@ import ( "sync" "testing" + "github.com/alcionai/clues" "github.com/google/uuid" "github.com/kopia/kopia/repo" "github.com/kopia/kopia/repo/manifest" @@ -12,7 +13,6 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/data" "github.com/alcionai/corso/src/internal/model" "github.com/alcionai/corso/src/internal/tester" diff --git a/src/internal/kopia/path_encoder_test.go b/src/internal/kopia/path_encoder_test.go index 9fccc0e7c..8e6031ddd 100644 --- a/src/internal/kopia/path_encoder_test.go +++ b/src/internal/kopia/path_encoder_test.go @@ -4,11 +4,11 @@ import ( "strings" "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/tester" ) diff --git a/src/internal/kopia/snapshot_manager.go b/src/internal/kopia/snapshot_manager.go index 6334af582..a25d52b92 100644 --- a/src/internal/kopia/snapshot_manager.go +++ b/src/internal/kopia/snapshot_manager.go @@ -7,7 +7,6 @@ import ( "github.com/alcionai/clues" "github.com/kopia/kopia/repo/manifest" "github.com/kopia/kopia/snapshot" - "github.com/pkg/errors" "golang.org/x/exp/maps" "github.com/alcionai/corso/src/pkg/logger" @@ -178,7 +177,7 @@ func fetchPrevManifests( metas, err := sm.FindManifests(ctx, allTags) if err != nil { - return nil, errors.Wrap(err, "fetching manifest metas by tag") + return nil, clues.Wrap(err, "fetching manifest metas by tag") } if len(metas) == 0 { @@ -207,7 +206,7 @@ func fetchPrevManifests( mans, err := sm.LoadSnapshots(ctx, ids) if err != nil { - return nil, errors.Wrap(err, "fetching previous manifests") + return nil, clues.Wrap(err, "fetching previous manifests") } found, hasCompleted := manifestsSinceLastComplete(ctx, mans) diff --git a/src/internal/kopia/upload.go b/src/internal/kopia/upload.go index b618e5d62..03c6a841a 100644 --- a/src/internal/kopia/upload.go +++ b/src/internal/kopia/upload.go @@ -20,7 +20,6 @@ import ( "github.com/kopia/kopia/fs/virtualfs" "github.com/kopia/kopia/repo/manifest" "github.com/kopia/kopia/snapshot/snapshotfs" - "github.com/pkg/errors" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/graph/metadata" @@ -97,7 +96,7 @@ func (rw *restoreStreamReader) checkVersion() error { for newlyRead := 0; newlyRead < versionSize; { n, err := rw.ReadCloser.Read(versionBuf[newlyRead:]) if err != nil { - return errors.Wrap(err, "reading data format version") + return clues.Wrap(err, "reading data format version") } newlyRead += n @@ -106,7 +105,7 @@ func (rw *restoreStreamReader) checkVersion() error { version := binary.BigEndian.Uint32(versionBuf) if version != rw.expectedVersion { - return errors.Errorf("unexpected data format %v", version) + return clues.New("unexpected data format").With("read_version", version) } return nil @@ -370,7 +369,7 @@ func collectionEntries( // For now assuming that item IDs don't need escaping. itemPath, err := streamedEnts.FullPath().Append(e.UUID(), true) if err != nil { - err = errors.Wrap(err, "getting full item path") + err = clues.Wrap(err, "getting full item path") progress.errs.AddRecoverable(err) logger.CtxErr(ctx, err).Error("getting full item path") @@ -443,14 +442,15 @@ func streamBaseEntries( } var ( - excludeSet map[string]struct{} - curPrefix string - curPathString = curPath.String() + excludeSet map[string]struct{} + curPrefix string ) + ctx = clues.Add(ctx, "current_item_path", curPath) + for prefix, excludes := range globalExcludeSet { // Select the set with the longest prefix to be most precise. - if strings.HasPrefix(curPathString, prefix) && len(prefix) >= len(curPrefix) { + if strings.HasPrefix(curPath.String(), prefix) && len(prefix) >= len(curPrefix) { excludeSet = excludes curPrefix = prefix } @@ -475,7 +475,7 @@ func streamBaseEntries( entName, err := decodeElement(entry.Name()) if err != nil { - return errors.Wrapf(err, "unable to decode entry name %s", entry.Name()) + return clues.Wrap(err, "decoding entry name: "+entry.Name()) } // This entry was marked as deleted by a service that can't tell us the @@ -487,7 +487,7 @@ func streamBaseEntries( // For now assuming that item IDs don't need escaping. itemPath, err := curPath.Append(entName, true) if err != nil { - return errors.Wrap(err, "getting full item path for base entry") + return clues.Wrap(err, "getting full item path for base entry") } // We need the previous path so we can find this item in the base snapshot's @@ -496,7 +496,7 @@ func streamBaseEntries( // to look for. prevItemPath, err := prevPath.Append(entName, true) if err != nil { - return errors.Wrap(err, "getting previous full item path for base entry") + return clues.Wrap(err, "getting previous full item path for base entry") } // Meta files aren't in backup details since it's the set of items the user @@ -520,17 +520,13 @@ func streamBaseEntries( } if err := cb(ctx, entry); err != nil { - return errors.Wrapf(err, "executing callback on item %q", itemPath) + return clues.Wrap(err, "executing callback on item").With("item_path", itemPath) } return nil }) if err != nil { - return errors.Wrapf( - err, - "traversing items in base snapshot directory %q", - curPath, - ) + return clues.Wrap(err, "traversing items in base snapshot directory") } return nil @@ -568,7 +564,7 @@ func getStreamItemFunc( seen, err := collectionEntries(ctx, cb, streamedEnts, progress) if err != nil { - return errors.Wrap(err, "streaming collection entries") + return clues.Wrap(err, "streaming collection entries") } if err := streamBaseEntries( @@ -582,7 +578,7 @@ func getStreamItemFunc( globalExcludeSet, progress, ); err != nil { - return errors.Wrap(err, "streaming base snapshot entries") + return clues.Wrap(err, "streaming base snapshot entries") } return nil @@ -738,15 +734,14 @@ func inflateCollectionTree( switch s.State() { case data.DeletedState: if s.PreviousPath() == nil { - return nil, nil, errors.Errorf("nil previous path on deleted collection") + return nil, nil, clues.New("nil previous path on deleted collection") } changedPaths = append(changedPaths, s.PreviousPath()) if _, ok := updatedPaths[s.PreviousPath().String()]; ok { - return nil, nil, errors.Errorf( - "multiple previous state changes to collection %s", - s.PreviousPath()) + return nil, nil, clues.New("multiple previous state changes to collection"). + With("collection_previous_path", s.PreviousPath()) } updatedPaths[s.PreviousPath().String()] = nil @@ -757,31 +752,26 @@ func inflateCollectionTree( changedPaths = append(changedPaths, s.PreviousPath()) if _, ok := updatedPaths[s.PreviousPath().String()]; ok { - return nil, nil, errors.Errorf( - "multiple previous state changes to collection %s", - s.PreviousPath(), - ) + return nil, nil, clues.New("multiple previous state changes to collection"). + With("collection_previous_path", s.PreviousPath()) } updatedPaths[s.PreviousPath().String()] = s.FullPath() } if s.FullPath() == nil || len(s.FullPath().Elements()) == 0 { - return nil, nil, errors.New("no identifier for collection") + return nil, nil, clues.New("no identifier for collection") } node := getTreeNode(roots, s.FullPath().Elements()) if node == nil { - return nil, nil, errors.Errorf( - "unable to get tree node for path %s", - s.FullPath(), - ) + return nil, nil, clues.New("getting tree node").With("collection_full_path", s.FullPath()) } // Make sure there's only a single collection adding items for any given // path in the new hierarchy. if node.collection != nil { - return nil, nil, errors.Errorf("multiple instances of collection at %s", s.FullPath()) + return nil, nil, clues.New("multiple instances of collection").With("collection_full_path", s.FullPath()) } node.collection = s @@ -799,7 +789,7 @@ func inflateCollectionTree( } if node.collection != nil && node.collection.State() == data.NotMovedState { - return nil, nil, errors.Errorf("conflicting states for collection %s", p) + return nil, nil, clues.New("conflicting states for collection").With("changed_path", p) } } @@ -808,11 +798,11 @@ func inflateCollectionTree( // traverseBaseDir is an unoptimized function that reads items in a directory // and traverses subdirectories in the given directory. oldDirPath is the path -// the directory would be at if the hierarchy was unchanged. newDirPath is the +// the directory would be at if the hierarchy was unchanged. expectedDirPath is the // path the directory would be at if all changes from the root to this directory // were taken into account. Both are needed to detect some changes like moving // a parent directory and moving one of the child directories out of the parent. -// If a directory on the path was deleted, newDirPath is set to nil. +// If a directory on the path was deleted, expectedDirPath is set to nil. // // TODO(ashmrtn): A potentially more memory efficient version of this would // traverse only the directories that we know are present in the collections @@ -823,12 +813,16 @@ func traverseBaseDir( depth int, updatedPaths map[string]path.Path, oldDirPath *path.Builder, - newDirPath *path.Builder, + expectedDirPath *path.Builder, dir fs.Directory, roots map[string]*treeMap, ) error { + ctx = clues.Add(ctx, + "old_dir_path", oldDirPath, + "expected_dir_path", expectedDirPath) + if depth >= maxInflateTraversalDepth { - return errors.Errorf("base snapshot tree too tall %s", oldDirPath) + return clues.New("base snapshot tree too tall") } // Wrapper base64 encodes all file and folder names to avoid issues with @@ -836,7 +830,7 @@ func traverseBaseDir( // from kopia we need to do the decoding here. dirName, err := decodeElement(dir.Name()) if err != nil { - return errors.Wrapf(err, "decoding base directory name %s", dir.Name()) + return clues.Wrap(err, "decoding base directory name").With("dir_name", dir.Name()) } // Form the path this directory would be at if the hierarchy remained the same @@ -849,7 +843,7 @@ func traverseBaseDir( // override any subtree movement with what's in updatedPaths if an entry // exists. oldDirPath = oldDirPath.Append(dirName) - currentPath := newDirPath + currentPath := expectedDirPath if currentPath != nil { currentPath = currentPath.Append(dirName) @@ -865,6 +859,8 @@ func traverseBaseDir( } } + ctx = clues.Add(ctx, "new_path", currentPath) + // TODO(ashmrtn): If we can do prefix matching on elements in updatedPaths and // we know that the tree node for this directory has no collection reference // and no child nodes then we can skip traversing this directory. This will @@ -892,7 +888,7 @@ func traverseBaseDir( ) }) if err != nil { - return errors.Wrapf(err, "traversing base directory %s", oldDirPath) + return clues.Wrap(err, "traversing base directory") } // We only need to add this base directory to the tree we're building if it @@ -909,7 +905,7 @@ func traverseBaseDir( // in the if-block though as that is an optimization. node := getTreeNode(roots, currentPath.Elements()) if node == nil { - return errors.Errorf("unable to get tree node for path %s", currentPath) + return clues.New("getting tree node") } // Now that we have the node we need to check if there is a collection @@ -924,18 +920,12 @@ func traverseBaseDir( curP, err := path.FromDataLayerPath(currentPath.String(), false) if err != nil { - return errors.Errorf( - "unable to convert current path %s to path.Path", - currentPath, - ) + return clues.New("converting current path to path.Path") } oldP, err := path.FromDataLayerPath(oldDirPath.String(), false) if err != nil { - return errors.Errorf( - "unable to convert old path %s to path.Path", - oldDirPath, - ) + return clues.New("converting old path to path.Path") } node.baseDir = dir @@ -1037,7 +1027,7 @@ func inflateDirTree( ) (fs.Directory, error) { roots, updatedPaths, err := inflateCollectionTree(ctx, collections) if err != nil { - return nil, errors.Wrap(err, "inflating collection tree") + return nil, clues.Wrap(err, "inflating collection tree") } baseIDs := make([]manifest.ID, 0, len(baseSnaps)) @@ -1055,12 +1045,12 @@ func inflateDirTree( for _, snap := range baseSnaps { if err = inflateBaseTree(ctx, loader, snap, updatedPaths, roots); err != nil { - return nil, errors.Wrap(err, "inflating base snapshot tree(s)") + return nil, clues.Wrap(err, "inflating base snapshot tree(s)") } } if len(roots) > 1 { - return nil, errors.New("multiple root directories") + return nil, clues.New("multiple root directories") } var res fs.Directory diff --git a/src/internal/kopia/upload_test.go b/src/internal/kopia/upload_test.go index 861dacf32..4c78df606 100644 --- a/src/internal/kopia/upload_test.go +++ b/src/internal/kopia/upload_test.go @@ -8,6 +8,7 @@ import ( "testing" "time" + "github.com/alcionai/clues" "github.com/kopia/kopia/fs" "github.com/kopia/kopia/fs/virtualfs" "github.com/kopia/kopia/repo/manifest" @@ -18,7 +19,6 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/mockconnector" "github.com/alcionai/corso/src/internal/data" "github.com/alcionai/corso/src/internal/tester" @@ -2374,7 +2374,7 @@ func (msw *mockMultiSnapshotWalker) SnapshotRoot(man *snapshot.Manifest) (fs.Ent return snap, nil } - return nil, errors.New("snapshot not found") + return nil, clues.New("snapshot not found") } func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTreeSelectsCorrectSubtrees() { diff --git a/src/internal/kopia/wrapper.go b/src/internal/kopia/wrapper.go index d088debda..b4229fdaf 100644 --- a/src/internal/kopia/wrapper.go +++ b/src/internal/kopia/wrapper.go @@ -11,7 +11,6 @@ import ( "github.com/kopia/kopia/snapshot" "github.com/kopia/kopia/snapshot/policy" "github.com/kopia/kopia/snapshot/snapshotfs" - "github.com/pkg/errors" "github.com/alcionai/corso/src/internal/data" D "github.com/alcionai/corso/src/internal/diagnostics" @@ -38,8 +37,8 @@ const ( ) var ( - errNotConnected = errors.New("not connected to repo") - errNoRestorePath = errors.New("no restore path given") + errNotConnected = clues.New("not connected to repo") + errNoRestorePath = clues.New("no restore path given") ) type BackupStats struct { @@ -88,7 +87,7 @@ func manifestToStats( func NewWrapper(c *conn) (*Wrapper, error) { if err := c.wrap(); err != nil { - return nil, errors.Wrap(err, "creating Wrapper") + return nil, clues.Wrap(err, "creating Wrapper") } return &Wrapper{c}, nil @@ -174,7 +173,7 @@ func (w Wrapper) BackupCollections( globalExcludeSet, progress) if err != nil { - return nil, nil, nil, errors.Wrap(err, "building kopia directories") + return nil, nil, nil, clues.Wrap(err, "building kopia directories") } s, err := w.makeSnapshotWithRoot( diff --git a/src/internal/kopia/wrapper_test.go b/src/internal/kopia/wrapper_test.go index 160e20c28..2f03a1fb2 100644 --- a/src/internal/kopia/wrapper_test.go +++ b/src/internal/kopia/wrapper_test.go @@ -7,6 +7,7 @@ import ( stdpath "path" "testing" + "github.com/alcionai/clues" "github.com/google/uuid" "github.com/kopia/kopia/repo" "github.com/kopia/kopia/repo/manifest" @@ -16,7 +17,6 @@ import ( "github.com/stretchr/testify/suite" "golang.org/x/exp/maps" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/mockconnector" "github.com/alcionai/corso/src/internal/connector/onedrive" "github.com/alcionai/corso/src/internal/data" diff --git a/src/internal/observe/observe_test.go b/src/internal/observe/observe_test.go index 9db84a348..31c818e05 100644 --- a/src/internal/observe/observe_test.go +++ b/src/internal/observe/observe_test.go @@ -10,11 +10,11 @@ import ( "testing" "time" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/tester" ) diff --git a/src/internal/operations/backup.go b/src/internal/operations/backup.go index c2111ed2e..2a8c44092 100644 --- a/src/internal/operations/backup.go +++ b/src/internal/operations/backup.go @@ -6,7 +6,6 @@ import ( "github.com/alcionai/clues" "github.com/google/uuid" - "github.com/pkg/errors" "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/common/crash" @@ -84,7 +83,7 @@ func NewBackupOperation( func (op BackupOperation) validate() error { if len(op.ResourceOwner) == 0 { - return errors.New("backup requires a resource owner") + return clues.New("backup requires a resource owner") } return op.operation.validate() @@ -164,7 +163,7 @@ func (op *BackupOperation) Run(ctx context.Context) (err error) { logger.Ctx(ctx). With("err", err). Errorw("running backup", clues.InErr(err).Slice()...) - op.Errors.Fail(errors.Wrap(err, "running backup")) + op.Errors.Fail(clues.Wrap(err, "running backup")) } LogFaultErrors(ctx, op.Errors.Errors(), "running backup") @@ -175,7 +174,7 @@ func (op *BackupOperation) Run(ctx context.Context) (err error) { err = op.persistResults(startTime, &opStats) if err != nil { - op.Errors.Fail(errors.Wrap(err, "persisting backup results")) + op.Errors.Fail(clues.Wrap(err, "persisting backup results")) return op.Errors.Failure() } @@ -189,7 +188,7 @@ func (op *BackupOperation) Run(ctx context.Context) (err error) { Infow("completed backup; conditional error forcing exit without model persistence", "results", op.Results) - return op.Errors.Fail(errors.Wrap(e, "forced backup")).Failure() + return op.Errors.Fail(clues.Wrap(e, "forced backup")).Failure() } } @@ -200,7 +199,7 @@ func (op *BackupOperation) Run(ctx context.Context) (err error) { op.Results.BackupID, deets.Details()) if err != nil { - op.Errors.Fail(errors.Wrap(err, "persisting backup")) + op.Errors.Fail(clues.Wrap(err, "persisting backup")) return op.Errors.Failure() } @@ -232,17 +231,17 @@ func (op *BackupOperation) do( op.incremental, op.Errors) if err != nil { - return nil, errors.Wrap(err, "producing manifests and metadata") + return nil, clues.Wrap(err, "producing manifests and metadata") } gc, err := connectToM365(ctx, op.Selectors, op.account, op.Errors) if err != nil { - return nil, errors.Wrap(err, "connectng to m365") + return nil, clues.Wrap(err, "connectng to m365") } cs, excludes, err := produceBackupDataCollections(ctx, gc, op.Selectors, mdColls, op.Options, op.Errors) if err != nil { - return nil, errors.Wrap(err, "producing backup data collections") + return nil, clues.Wrap(err, "producing backup data collections") } ctx = clues.Add(ctx, "coll_count", len(cs)) @@ -259,7 +258,7 @@ func (op *BackupOperation) do( op.incremental && canUseMetaData, op.Errors) if err != nil { - return nil, errors.Wrap(err, "persisting collection backups") + return nil, clues.Wrap(err, "persisting collection backups") } opStats.k = writeStats @@ -273,7 +272,7 @@ func (op *BackupOperation) do( deets, op.Errors) if err != nil { - return nil, errors.Wrap(err, "merging details") + return nil, clues.Wrap(err, "merging details") } opStats.gc = gc.AwaitStatus() @@ -426,7 +425,7 @@ func consumeBackupDataCollections( for _, reason := range m.Reasons { pb, err := builderFromReason(ctx, tenantID, reason) if err != nil { - return nil, nil, nil, errors.Wrap(err, "getting subtree paths for bases") + return nil, nil, nil, clues.Wrap(err, "getting subtree paths for bases") } paths = append(paths, pb) @@ -647,7 +646,7 @@ func (op *BackupOperation) persistResults( if opStats.k == nil { op.Status = Failed - return errors.New("backup persistence never completed") + return clues.New("backup persistence never completed") } op.Results.BytesRead = opStats.k.TotalHashedBytes @@ -657,7 +656,7 @@ func (op *BackupOperation) persistResults( if opStats.gc == nil { op.Status = Failed - return errors.New("backup population never completed") + return clues.New("backup population never completed") } if op.Status != Failed && opStats.gc.Metrics.Successes == 0 { diff --git a/src/internal/operations/backup_integration_test.go b/src/internal/operations/backup_integration_test.go index 78b4efcb2..dbaa272dc 100644 --- a/src/internal/operations/backup_integration_test.go +++ b/src/internal/operations/backup_integration_test.go @@ -6,17 +6,16 @@ import ( "testing" "time" + "github.com/alcionai/clues" "github.com/google/uuid" "github.com/microsoftgraph/msgraph-sdk-go/drive" "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/microsoftgraph/msgraph-sdk-go/users" - "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" "golang.org/x/exp/maps" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector" @@ -448,7 +447,7 @@ func toDataLayerPath( case path.OneDriveService: p, err = pb.ToDataLayerOneDrivePath(tenant, user, isItem) default: - err = errors.Errorf("unknown service %s", service.String()) + err = clues.New(fmt.Sprintf("unknown service: %s", service)) } require.NoError(t, err, clues.ToCore(err)) diff --git a/src/internal/operations/backup_test.go b/src/internal/operations/backup_test.go index b1cce45cb..c18c2403d 100644 --- a/src/internal/operations/backup_test.go +++ b/src/internal/operations/backup_test.go @@ -2,18 +2,18 @@ package operations import ( "context" + "fmt" stdpath "path" "testing" "time" + "github.com/alcionai/clues" "github.com/kopia/kopia/repo/manifest" "github.com/kopia/kopia/snapshot" - "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector/support" "github.com/alcionai/corso/src/internal/data" evmock "github.com/alcionai/corso/src/internal/events/mock" @@ -123,18 +123,24 @@ func (mbs mockBackupStorer) Get( id model.StableID, toPopulate model.Model, ) error { + ctx = clues.Add( + ctx, + "model_schema", s, + "model_id", id, + "model_type", fmt.Sprintf("%T", toPopulate)) + if s != model.BackupSchema { - return errors.Errorf("unexpected schema %s", s) + return clues.New("unexpected schema").WithClues(ctx) } r, ok := mbs.entries[id] if !ok { - return errors.Errorf("model with id %s not found", id) + return clues.New("model not found").WithClues(ctx) } bu, ok := toPopulate.(*backup.Backup) if !ok { - return errors.Errorf("bad input type %T", toPopulate) + return clues.New("bad population type").WithClues(ctx) } *bu = r @@ -143,11 +149,11 @@ func (mbs mockBackupStorer) Get( } func (mbs mockBackupStorer) Delete(context.Context, model.Schema, model.StableID) error { - return errors.New("not implemented") + return clues.New("not implemented") } func (mbs mockBackupStorer) DeleteWithModelStoreID(context.Context, manifest.ID) error { - return errors.New("not implemented") + return clues.New("not implemented") } func (mbs mockBackupStorer) GetIDsForType( @@ -155,7 +161,7 @@ func (mbs mockBackupStorer) GetIDsForType( model.Schema, map[string]string, ) ([]*model.BaseModel, error) { - return nil, errors.New("not implemented") + return nil, clues.New("not implemented") } func (mbs mockBackupStorer) GetWithModelStoreID( @@ -164,15 +170,15 @@ func (mbs mockBackupStorer) GetWithModelStoreID( manifest.ID, model.Model, ) error { - return errors.New("not implemented") + return clues.New("not implemented") } func (mbs mockBackupStorer) Put(context.Context, model.Schema, model.Model) error { - return errors.New("not implemented") + return clues.New("not implemented") } func (mbs mockBackupStorer) Update(context.Context, model.Schema, model.Model) error { - return errors.New("not implemented") + return clues.New("not implemented") } // --------------------------------------------------------------------------- diff --git a/src/internal/operations/common.go b/src/internal/operations/common.go index 98bbe2b90..feec1e8d7 100644 --- a/src/internal/operations/common.go +++ b/src/internal/operations/common.go @@ -4,7 +4,6 @@ import ( "context" "github.com/alcionai/clues" - "github.com/pkg/errors" "github.com/alcionai/corso/src/internal/model" "github.com/alcionai/corso/src/internal/streamstore" @@ -23,7 +22,7 @@ func getBackupAndDetailsFromID( ) (*backup.Backup, *details.Details, error) { bup, err := ms.GetBackup(ctx, backupID) if err != nil { - return nil, nil, errors.Wrap(err, "getting backup details ID") + return nil, nil, clues.Wrap(err, "getting backup details ID") } var ( @@ -41,7 +40,7 @@ func getBackupAndDetailsFromID( } if err := detailsStore.Read(ctx, ssid, umt, errs); err != nil { - return nil, nil, errors.Wrap(err, "reading backup data from streamstore") + return nil, nil, clues.Wrap(err, "reading backup data from streamstore") } return bup, &deets, nil diff --git a/src/internal/operations/manifests.go b/src/internal/operations/manifests.go index a30819467..b4505c915 100644 --- a/src/internal/operations/manifests.go +++ b/src/internal/operations/manifests.go @@ -102,7 +102,7 @@ func produceManifestsAndMetadata( } if err != nil { - return nil, nil, false, errors.Wrap(err, "retrieving prior backup data") + return nil, nil, false, clues.Wrap(err, "retrieving prior backup data") } ssid := bup.StreamStoreID @@ -206,7 +206,7 @@ func collectMetadata( // Restore is best-effort and we want to keep it that way since we want to // return as much metadata as we can to reduce the work we'll need to do. // Just wrap the error here for better reporting/debugging. - return dcs, errors.Wrap(err, "collecting prior metadata") + return dcs, clues.Wrap(err, "collecting prior metadata") } return dcs, nil diff --git a/src/internal/operations/manifests_test.go b/src/internal/operations/manifests_test.go index 0611db4ec..df0c54632 100644 --- a/src/internal/operations/manifests_test.go +++ b/src/internal/operations/manifests_test.go @@ -4,12 +4,12 @@ import ( "context" "testing" + "github.com/alcionai/clues" "github.com/kopia/kopia/repo/manifest" "github.com/kopia/kopia/snapshot" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/data" "github.com/alcionai/corso/src/internal/kopia" "github.com/alcionai/corso/src/internal/model" diff --git a/src/internal/operations/operation.go b/src/internal/operations/operation.go index 1e32e6258..8136c0905 100644 --- a/src/internal/operations/operation.go +++ b/src/internal/operations/operation.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/pkg/errors" + "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/connector" "github.com/alcionai/corso/src/internal/connector/graph" @@ -85,11 +85,11 @@ func newOperation( func (op operation) validate() error { if op.kopia == nil { - return errors.New("missing kopia connection") + return clues.New("missing kopia connection") } if op.store == nil { - return errors.New("missing modelstore") + return clues.New("missing modelstore") } return nil diff --git a/src/internal/operations/operation_test.go b/src/internal/operations/operation_test.go index 31aad18be..27cf6185f 100644 --- a/src/internal/operations/operation_test.go +++ b/src/internal/operations/operation_test.go @@ -4,10 +4,10 @@ import ( "testing" "time" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/events" "github.com/alcionai/corso/src/internal/kopia" "github.com/alcionai/corso/src/internal/tester" diff --git a/src/internal/operations/restore.go b/src/internal/operations/restore.go index b6e953f5b..b1380ada0 100644 --- a/src/internal/operations/restore.go +++ b/src/internal/operations/restore.go @@ -7,7 +7,6 @@ import ( "github.com/alcionai/clues" "github.com/google/uuid" - "github.com/pkg/errors" "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/common/crash" @@ -150,7 +149,7 @@ func (op *RestoreOperation) Run(ctx context.Context) (restoreDetails *details.De logger.Ctx(ctx). With("err", err). Errorw("running restore", clues.InErr(err).Slice()...) - op.Errors.Fail(errors.Wrap(err, "running restore")) + op.Errors.Fail(clues.Wrap(err, "running restore")) } LogFaultErrors(ctx, op.Errors.Errors(), "running restore") @@ -161,7 +160,7 @@ func (op *RestoreOperation) Run(ctx context.Context) (restoreDetails *details.De err = op.persistResults(ctx, start, &opStats) if err != nil { - op.Errors.Fail(errors.Wrap(err, "persisting restore results")) + op.Errors.Fail(clues.Wrap(err, "persisting restore results")) return nil, op.Errors.Failure() } @@ -183,14 +182,14 @@ func (op *RestoreOperation) do( detailsStore, op.Errors) if err != nil { - return nil, errors.Wrap(err, "getting backup and details") + return nil, clues.Wrap(err, "getting backup and details") } observe.Message(ctx, observe.Safe("Restoring"), observe.Bullet, observe.PII(bup.Selector.DiscreteOwner)) paths, err := formatDetailsForRestoration(ctx, bup.Version, op.Selectors, deets, op.Errors) if err != nil { - return nil, errors.Wrap(err, "formatting paths from details") + return nil, clues.Wrap(err, "formatting paths from details") } ctx = clues.Add( @@ -220,7 +219,7 @@ func (op *RestoreOperation) do( dcs, err := op.kopia.RestoreMultipleItems(ctx, bup.SnapshotID, paths, opStats.bytesRead, op.Errors) if err != nil { - return nil, errors.Wrap(err, "producing collections to restore") + return nil, clues.Wrap(err, "producing collections to restore") } kopiaComplete <- struct{}{} @@ -233,7 +232,7 @@ func (op *RestoreOperation) do( gc, err := connectToM365(ctx, op.Selectors, op.account, op.Errors) if err != nil { - return nil, errors.Wrap(err, "connecting to M365") + return nil, clues.Wrap(err, "connecting to M365") } restoreComplete, closer := observe.MessageWithCompletion(ctx, observe.Safe("Restoring data")) @@ -250,7 +249,7 @@ func (op *RestoreOperation) do( dcs, op.Errors) if err != nil { - return nil, errors.Wrap(err, "restoring collections") + return nil, clues.Wrap(err, "restoring collections") } restoreComplete <- struct{}{} @@ -283,7 +282,7 @@ func (op *RestoreOperation) persistResults( if opStats.gc == nil { op.Status = Failed - return errors.New("restoration never completed") + return clues.New("restoration never completed") } if op.Status != Failed && opStats.gc.Metrics.Successes == 0 { diff --git a/src/internal/operations/restore_test.go b/src/internal/operations/restore_test.go index 4d0335113..d0d10b104 100644 --- a/src/internal/operations/restore_test.go +++ b/src/internal/operations/restore_test.go @@ -5,11 +5,11 @@ import ( "testing" "time" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/connector/exchange" "github.com/alcionai/corso/src/internal/connector/graph" diff --git a/src/internal/streamstore/mock/mock.go b/src/internal/streamstore/mock/mock.go index f7ce2cd6a..ef1f51e53 100644 --- a/src/internal/streamstore/mock/mock.go +++ b/src/internal/streamstore/mock/mock.go @@ -5,12 +5,11 @@ import ( "context" "io" - "github.com/pkg/errors" - "github.com/alcionai/clues" - "github.com/alcionai/corso/src/internal/streamstore" "github.com/alcionai/corso/src/pkg/backup/details" "github.com/alcionai/corso/src/pkg/fault" + + "github.com/alcionai/corso/src/internal/streamstore" ) var _ streamstore.Streamer = &Streamer{} @@ -30,6 +29,11 @@ func (ms Streamer) Read( col streamstore.Collectable, errs *fault.Bus, ) error { + ctx = clues.Add( + ctx, + "read_snapshot_id", snapshotID, + "collectable_type", col.Type) + var mr streamstore.Marshaller switch col.Type { @@ -38,11 +42,11 @@ func (ms Streamer) Read( case streamstore.FaultErrorsType: mr = ms.Errors[snapshotID] default: - return clues.New("unknown type: " + col.Type) + return clues.New("unknown type: " + col.Type).WithClues(ctx) } if mr == nil { - return errors.Errorf("no marshaller for %s ID %s", col.Type, snapshotID) + return clues.New("collectable " + col.Type + " has no marshaller").WithClues(ctx) } bs, err := mr.Marshal() diff --git a/src/internal/streamstore/streamstore.go b/src/internal/streamstore/streamstore.go index a9dab4810..ec728df67 100644 --- a/src/internal/streamstore/streamstore.go +++ b/src/internal/streamstore/streamstore.go @@ -8,7 +8,6 @@ import ( "io" "github.com/alcionai/clues" - "github.com/pkg/errors" "github.com/alcionai/corso/src/internal/data" "github.com/alcionai/corso/src/internal/kopia" @@ -83,7 +82,7 @@ func (ss *storeStreamer) Read(ctx context.Context, snapshotID string, col Collec func (ss *storeStreamer) Delete(ctx context.Context, detailsID string) error { err := ss.kw.DeleteSnapshot(ctx, detailsID) if err != nil { - return errors.Wrap(err, "deleting snapshot in stream store") + return clues.Wrap(err, "deleting snapshot in stream store") } return nil @@ -250,7 +249,7 @@ func write( false, errs) if err != nil { - return "", errors.Wrap(err, "storing marshalled bytes in repository") + return "", clues.Wrap(err, "storing marshalled bytes in repository") } return backupStats.SnapshotID, nil @@ -293,7 +292,7 @@ func read( &stats.ByteCounter{}, errs) if err != nil { - return errors.Wrap(err, "retrieving data") + return clues.Wrap(err, "retrieving data") } // Expect only 1 data collection diff --git a/src/internal/tester/account.go b/src/internal/tester/account.go index 5615c038b..94552c771 100644 --- a/src/internal/tester/account.go +++ b/src/internal/tester/account.go @@ -3,9 +3,9 @@ package tester import ( "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/require" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/credentials" ) diff --git a/src/internal/tester/config.go b/src/internal/tester/config.go index 000012b2c..615f4018a 100644 --- a/src/internal/tester/config.go +++ b/src/internal/tester/config.go @@ -6,12 +6,11 @@ import ( "strings" "testing" - "github.com/pkg/errors" + "github.com/alcionai/clues" "github.com/spf13/viper" "github.com/stretchr/testify/require" "golang.org/x/exp/maps" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/pkg/account" ) @@ -65,7 +64,7 @@ func NewTestViper() (*viper.Viper, error) { // Or use a custom file location ext := filepath.Ext(configFilePath) if len(ext) == 0 { - return nil, errors.New("corso_test requires an extension") + return nil, clues.New("corso_test requires an extension") } vpr.SetConfigFile(configFilePath) @@ -96,7 +95,7 @@ func readTestConfig() (map[string]string, error) { if err = vpr.ReadInConfig(); err != nil { _, ok := err.(viper.ConfigFileNotFoundError) if !ok { - return nil, errors.Wrap(err, "reading config file: "+viper.ConfigFileUsed()) + return nil, clues.Wrap(err, "reading config file: "+viper.ConfigFileUsed()) } } diff --git a/src/internal/tester/storage.go b/src/internal/tester/storage.go index c0523cb09..f5d903767 100644 --- a/src/internal/tester/storage.go +++ b/src/internal/tester/storage.go @@ -3,9 +3,9 @@ package tester import ( "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/require" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/pkg/credentials" "github.com/alcionai/corso/src/pkg/storage" ) diff --git a/src/pkg/account/account.go b/src/pkg/account/account.go index f501f428f..12b8d679c 100644 --- a/src/pkg/account/account.go +++ b/src/pkg/account/account.go @@ -1,7 +1,7 @@ package account import ( - "errors" + "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common" ) @@ -16,7 +16,7 @@ const ( // storage parsing errors var ( - errMissingRequired = errors.New("missing required storage configuration") + errMissingRequired = clues.New("missing required storage configuration") ) // Account defines an account provider, along with any credentials diff --git a/src/pkg/account/m365.go b/src/pkg/account/m365.go index b9f91b8aa..38d6efc88 100644 --- a/src/pkg/account/m365.go +++ b/src/pkg/account/m365.go @@ -2,7 +2,6 @@ package account import ( "github.com/alcionai/clues" - "github.com/pkg/errors" "github.com/alcionai/corso/src/pkg/credentials" ) @@ -67,7 +66,7 @@ func (c M365Config) validate() error { for k, v := range check { if len(v) == 0 { - return clues.Stack(errMissingRequired, errors.New(k)) + return clues.Stack(errMissingRequired, clues.New(k)) } } diff --git a/src/pkg/account/m365_test.go b/src/pkg/account/m365_test.go index ddabb1997..44cf49c94 100644 --- a/src/pkg/account/m365_test.go +++ b/src/pkg/account/m365_test.go @@ -3,11 +3,11 @@ package account_test import ( "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/credentials" ) diff --git a/src/pkg/backup/details/details_test.go b/src/pkg/backup/details/details_test.go index 189f72a9f..633fc0fdf 100644 --- a/src/pkg/backup/details/details_test.go +++ b/src/pkg/backup/details/details_test.go @@ -6,11 +6,11 @@ import ( "testing" "time" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/path" diff --git a/src/pkg/credentials/aws.go b/src/pkg/credentials/aws.go index 9ab9d7c3e..07d993999 100644 --- a/src/pkg/credentials/aws.go +++ b/src/pkg/credentials/aws.go @@ -4,7 +4,6 @@ import ( "os" "github.com/alcionai/clues" - "github.com/pkg/errors" ) // envvar consts @@ -49,7 +48,7 @@ func (c AWS) Validate() error { for k, v := range check { if len(v) == 0 { - return clues.Stack(errMissingRequired, errors.New(k)) + return clues.Stack(errMissingRequired, clues.New(k)) } } diff --git a/src/pkg/credentials/corso.go b/src/pkg/credentials/corso.go index fc22dc957..44f088c5f 100644 --- a/src/pkg/credentials/corso.go +++ b/src/pkg/credentials/corso.go @@ -4,7 +4,6 @@ import ( "os" "github.com/alcionai/clues" - "github.com/pkg/errors" ) // envvar consts @@ -35,7 +34,7 @@ func (c Corso) Validate() error { for k, v := range check { if len(v) == 0 { - return clues.Stack(errMissingRequired, errors.New(k)) + return clues.Stack(errMissingRequired, clues.New(k)) } } diff --git a/src/pkg/credentials/credentials.go b/src/pkg/credentials/credentials.go index feffa749a..e8d5011c5 100644 --- a/src/pkg/credentials/credentials.go +++ b/src/pkg/credentials/credentials.go @@ -1,5 +1,5 @@ package credentials -import "errors" +import "github.com/alcionai/clues" -var errMissingRequired = errors.New("missing required storage configuration") +var errMissingRequired = clues.New("missing required storage configuration") diff --git a/src/pkg/credentials/m365.go b/src/pkg/credentials/m365.go index c2d0c5906..d6fcaf030 100644 --- a/src/pkg/credentials/m365.go +++ b/src/pkg/credentials/m365.go @@ -4,7 +4,6 @@ import ( "os" "github.com/alcionai/clues" - "github.com/pkg/errors" ) // envvar consts @@ -37,7 +36,7 @@ func (c M365) Validate() error { for k, v := range check { if len(v) == 0 { - return clues.Stack(errMissingRequired, errors.New(k)) + return clues.Stack(errMissingRequired, clues.New(k)) } } diff --git a/src/pkg/fault/example_fault_test.go b/src/pkg/fault/example_fault_test.go index 832a17df0..222d52270 100644 --- a/src/pkg/fault/example_fault_test.go +++ b/src/pkg/fault/example_fault_test.go @@ -3,7 +3,7 @@ package fault_test import ( "fmt" - "github.com/pkg/errors" + "github.com/alcionai/clues" "github.com/alcionai/corso/src/pkg/fault" ) @@ -37,7 +37,7 @@ func (m mockOper) Run() *fault.Bus { return m.Errors } type mockDepenedency struct{} func (md mockDepenedency) do() error { - return errors.New("caught one") + return clues.New("caught one") } var dependency = mockDepenedency{} @@ -87,7 +87,7 @@ func ExampleBus_Fail() { lowLevelCall := func() error { if err := dependencyCall(); err != nil { // wrap here, deeper into the stack - return errors.Wrap(err, "dependency") + return clues.Wrap(err, "dependency") } return nil @@ -122,7 +122,7 @@ func ExampleBus_AddRecoverable() { if err := getIthItem(i); err != nil { // lower level calls don't AddRecoverable to the fault.Bus. // they stick to normal golang error handling. - return errors.Wrap(err, "dependency") + return clues.Wrap(err, "dependency") } return nil @@ -158,7 +158,7 @@ func ExampleBus_AddRecoverable() { // ExampleBus_Failure describes retrieving the non-recoverable error. func ExampleBus_Failure() { errs := fault.New(false) - errs.Fail(errors.New("catastrophe")) + errs.Fail(clues.New("catastrophe")) // Failure() returns the primary failure. err := errs.Failure() @@ -166,7 +166,7 @@ func ExampleBus_Failure() { // if multiple Failures occur, each one after the first gets // added to the Recoverable slice as an overflow measure. - errs.Fail(errors.New("another catastrophe")) + errs.Fail(clues.New("another catastrophe")) errSl := errs.Recovered() for _, e := range errSl { @@ -181,7 +181,7 @@ func ExampleBus_Failure() { // If failFast is set to true, then the first recoerable error Added gets // promoted to the Err() position. errs = fault.New(true) - errs.AddRecoverable(errors.New("not catastrophic, but still becomes the Failure()")) + errs.AddRecoverable(clues.New("not catastrophic, but still becomes the Failure()")) err = errs.Failure() fmt.Println(err) @@ -194,8 +194,8 @@ func ExampleBus_Failure() { // recover from and continue. func ExampleErrors_Recovered() { errs := fault.New(false) - errs.AddRecoverable(errors.New("not catastrophic")) - errs.AddRecoverable(errors.New("something unwanted")) + errs.AddRecoverable(clues.New("not catastrophic")) + errs.AddRecoverable(clues.New("something unwanted")) // Recovered() gets the slice of all recoverable errors added during // the run, but which did not cause a failure. @@ -314,7 +314,7 @@ func Example_e2e() { // we're not passing in or calling fault.Bus here, // because this isn't the iteration handler, it's just // a regular error. - return errors.Wrap(err, "dependency") + return clues.Wrap(err, "dependency") } return nil @@ -364,7 +364,7 @@ func ExampleErrors_Failure_return() { // handling whenever possible. fn := func() error { if err := dependency.do(); err != nil { - return errors.Wrap(err, "direct") + return clues.Wrap(err, "direct") } return nil @@ -383,7 +383,7 @@ func ExampleErrors_Failure_return() { } if err := dependency.do(); err != nil { - errs.AddRecoverable(errors.Wrap(err, "recoverable")) + errs.AddRecoverable(clues.Wrap(err, "recoverable")) } } diff --git a/src/pkg/fault/fault_test.go b/src/pkg/fault/fault_test.go index c12016e51..a56ddcc03 100644 --- a/src/pkg/fault/fault_test.go +++ b/src/pkg/fault/fault_test.go @@ -2,7 +2,6 @@ package fault_test import ( "encoding/json" - "errors" "fmt" "testing" @@ -206,9 +205,9 @@ func (suite *FaultErrorsUnitSuite) TestErrors() { n := fault.New(false) require.NotNil(t, n) - n.Fail(errors.New("fail")) - n.AddRecoverable(errors.New("1")) - n.AddRecoverable(errors.New("2")) + n.Fail(clues.New("fail")) + n.AddRecoverable(clues.New("1")) + n.AddRecoverable(clues.New("2")) d := n.Errors() assert.Equal(t, clues.ToCore(n.Failure()), d.Failure) @@ -219,9 +218,9 @@ func (suite *FaultErrorsUnitSuite) TestErrors() { n = fault.New(true) require.NotNil(t, n) - n.Fail(errors.New("fail")) - n.AddRecoverable(errors.New("1")) - n.AddRecoverable(errors.New("2")) + n.Fail(clues.New("fail")) + n.AddRecoverable(clues.New("1")) + n.AddRecoverable(clues.New("2")) d = n.Errors() assert.Equal(t, clues.ToCore(n.Failure()), d.Failure) @@ -369,8 +368,8 @@ func (suite *FaultErrorsUnitSuite) TestMarshalUnmarshal() { n := fault.New(false) require.NotNil(t, n) - n.AddRecoverable(errors.New("1")) - n.AddRecoverable(errors.New("2")) + n.AddRecoverable(clues.New("1")) + n.AddRecoverable(clues.New("2")) bs, err := json.Marshal(n.Errors()) require.NoError(t, err, clues.ToCore(err)) diff --git a/src/pkg/fault/item_test.go b/src/pkg/fault/item_test.go index 1fb9dc78a..18fce66f7 100644 --- a/src/pkg/fault/item_test.go +++ b/src/pkg/fault/item_test.go @@ -3,7 +3,7 @@ package fault import ( "testing" - "github.com/pkg/errors" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" @@ -36,7 +36,7 @@ func (suite *ItemUnitSuite) TestItem_Error() { func (suite *ItemUnitSuite) TestContainerErr() { t := suite.T() addtl := map[string]any{"foo": "bar"} - i := ContainerErr(errors.New("foo"), "id", "name", addtl) + i := ContainerErr(clues.New("foo"), "id", "name", addtl) expect := Item{ ID: "id", @@ -52,7 +52,7 @@ func (suite *ItemUnitSuite) TestContainerErr() { func (suite *ItemUnitSuite) TestFileErr() { t := suite.T() addtl := map[string]any{"foo": "bar"} - i := FileErr(errors.New("foo"), "id", "name", addtl) + i := FileErr(clues.New("foo"), "id", "name", addtl) expect := Item{ ID: "id", @@ -68,7 +68,7 @@ func (suite *ItemUnitSuite) TestFileErr() { func (suite *ItemUnitSuite) TestOwnerErr() { t := suite.T() addtl := map[string]any{"foo": "bar"} - i := OwnerErr(errors.New("foo"), "id", "name", addtl) + i := OwnerErr(clues.New("foo"), "id", "name", addtl) expect := Item{ ID: "id", diff --git a/src/pkg/fault/testdata/testdata.go b/src/pkg/fault/testdata/testdata.go index 0a28f6ccb..8b3cf7bb8 100644 --- a/src/pkg/fault/testdata/testdata.go +++ b/src/pkg/fault/testdata/testdata.go @@ -1,9 +1,9 @@ package testdata import ( + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/pkg/fault" ) diff --git a/src/pkg/path/onedrive_test.go b/src/pkg/path/onedrive_test.go index 8fdafaf42..9a44a0e7a 100644 --- a/src/pkg/path/onedrive_test.go +++ b/src/pkg/path/onedrive_test.go @@ -3,11 +3,11 @@ package path_test import ( "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/path" ) diff --git a/src/pkg/path/path.go b/src/pkg/path/path.go index 0d7bc95ca..1af05a8c8 100644 --- a/src/pkg/path/path.go +++ b/src/pkg/path/path.go @@ -57,7 +57,6 @@ import ( "strings" "github.com/alcionai/clues" - "github.com/pkg/errors" ) const ( @@ -73,8 +72,8 @@ var charactersToEscape = map[rune]struct{}{ } var ( - errMissingSegment = errors.New("missing required path element") - errParsingPath = errors.New("parsing resource path") + errMissingSegment = clues.New("missing required path element") + errParsingPath = clues.New("parsing resource path") ) // For now, adding generic functions to pull information from segments. @@ -268,11 +267,11 @@ func (pb Builder) Elements() []string { func verifyInputValues(tenant, resourceOwner string) error { if len(tenant) == 0 { - return clues.Stack(errMissingSegment, errors.New("tenant")) + return clues.Stack(errMissingSegment, clues.New("tenant")) } if len(resourceOwner) == 0 { - return clues.Stack(errMissingSegment, errors.New("resourceOwner")) + return clues.Stack(errMissingSegment, clues.New("resourceOwner")) } return nil @@ -284,7 +283,7 @@ func (pb Builder) verifyPrefix(tenant, resourceOwner string) error { } if len(pb.elements) == 0 { - return errors.New("missing path beyond prefix") + return clues.New("missing path beyond prefix") } return nil @@ -307,7 +306,7 @@ func (pb Builder) ToStreamStorePath( } if isItem && len(pb.elements) == 0 { - return nil, errors.New("missing path beyond prefix") + return nil, clues.New("missing path beyond prefix") } metadataService := UnknownService @@ -348,7 +347,7 @@ func (pb Builder) ToServiceCategoryMetadataPath( } if isItem && len(pb.elements) == 0 { - return nil, errors.New("missing path beyond prefix") + return nil, clues.New("missing path beyond prefix") } metadataService := UnknownService @@ -566,7 +565,7 @@ func validateEscapedElement(element string) error { } if prevWasEscape { - return errors.New("trailing escape character") + return clues.New("trailing escape character") } return nil diff --git a/src/pkg/path/path_test.go b/src/pkg/path/path_test.go index caca01754..4c945553a 100644 --- a/src/pkg/path/path_test.go +++ b/src/pkg/path/path_test.go @@ -5,11 +5,11 @@ import ( "strings" "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/tester" ) diff --git a/src/pkg/path/resource_path.go b/src/pkg/path/resource_path.go index b1a64449a..c7f570b14 100644 --- a/src/pkg/path/resource_path.go +++ b/src/pkg/path/resource_path.go @@ -5,10 +5,9 @@ import ( "strings" "github.com/alcionai/clues" - "github.com/pkg/errors" ) -var ErrorUnknownService = errors.New("unknown service string") +var ErrorUnknownService = clues.New("unknown service string") // ServiceType denotes what service the path corresponds to. Metadata services // are also included though they are only used for paths that house metadata for @@ -54,7 +53,7 @@ func toServiceType(service string) ServiceType { } } -var ErrorUnknownCategory = errors.New("unknown category string") +var ErrorUnknownCategory = clues.New("unknown category string") // CategoryType denotes what category of data the path corresponds to. The order // of the enums below can be changed, but the string representation of each enum @@ -256,7 +255,7 @@ func (rp dataLayerResourcePath) Append( isItem bool, ) (Path, error) { if rp.hasItem { - return nil, errors.New("appending to an item path") + return nil, clues.New("appending to an item path") } return &dataLayerResourcePath{ diff --git a/src/pkg/path/resource_path_test.go b/src/pkg/path/resource_path_test.go index fa9f94d6e..84cc79761 100644 --- a/src/pkg/path/resource_path_test.go +++ b/src/pkg/path/resource_path_test.go @@ -5,11 +5,11 @@ import ( "strings" "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/path" ) diff --git a/src/pkg/path/service_category_test.go b/src/pkg/path/service_category_test.go index 63211e262..d2b19b244 100644 --- a/src/pkg/path/service_category_test.go +++ b/src/pkg/path/service_category_test.go @@ -4,10 +4,10 @@ import ( "strings" "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/tester" ) diff --git a/src/pkg/repository/loadtest/repository_load_test.go b/src/pkg/repository/loadtest/repository_load_test.go index 07f8bc438..72093a27f 100644 --- a/src/pkg/repository/loadtest/repository_load_test.go +++ b/src/pkg/repository/loadtest/repository_load_test.go @@ -8,11 +8,11 @@ import ( "sort" "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" D "github.com/alcionai/corso/src/internal/diagnostics" "github.com/alcionai/corso/src/internal/operations" "github.com/alcionai/corso/src/internal/tester" diff --git a/src/pkg/repository/repository.go b/src/pkg/repository/repository.go index 874b3a04f..fab25266f 100644 --- a/src/pkg/repository/repository.go +++ b/src/pkg/repository/repository.go @@ -28,7 +28,7 @@ import ( "github.com/alcionai/corso/src/pkg/store" ) -var ErrorRepoAlreadyExists = errors.New("a repository was already initialized with that configuration") +var ErrorRepoAlreadyExists = clues.New("a repository was already initialized with that configuration") // BackupGetter deals with retrieving metadata about backups from the // repository. @@ -115,7 +115,7 @@ func Initialize( return nil, clues.Stack(ErrorRepoAlreadyExists, err).WithClues(ctx) } - return nil, errors.Wrap(err, "initializing kopia") + return nil, clues.Wrap(err, "initializing kopia") } // kopiaRef comes with a count of 1 and NewWrapper/NewModelStore bumps it again so safe // to close here. @@ -133,7 +133,7 @@ func Initialize( bus, err := events.NewBus(ctx, s, acct.ID(), opts) if err != nil { - return nil, errors.Wrap(err, "constructing event bus") + return nil, clues.Wrap(err, "constructing event bus") } repoID := newRepoID(s) @@ -192,7 +192,7 @@ func Connect( kopiaRef := kopia.NewConn(s) if err := kopiaRef.Connect(ctx); err != nil { - return nil, errors.Wrap(err, "connecting kopia client") + return nil, clues.Wrap(err, "connecting kopia client") } // kopiaRef comes with a count of 1 and NewWrapper/NewModelStore bumps it again so safe // to close here. @@ -210,7 +210,7 @@ func Connect( bus, err := events.NewBus(ctx, s, acct.ID(), opts) if err != nil { - return nil, errors.Wrap(err, "constructing event bus") + return nil, clues.Wrap(err, "constructing event bus") } rm := &repositoryModel{} @@ -219,7 +219,7 @@ func Connect( if !opts.DisableMetrics { rm, err = getRepoModel(ctx, ms) if err != nil { - return nil, errors.New("retrieving repo info") + return nil, clues.New("retrieving repo info") } bus.SetRepoID(string(rm.ID)) diff --git a/src/pkg/repository/repository_test.go b/src/pkg/repository/repository_test.go index 020dccaf8..cdea26d27 100644 --- a/src/pkg/repository/repository_test.go +++ b/src/pkg/repository/repository_test.go @@ -3,11 +3,11 @@ package repository_test import ( "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/control" diff --git a/src/pkg/repository/repository_unexported_test.go b/src/pkg/repository/repository_unexported_test.go index 2bceff5c9..2837978c3 100644 --- a/src/pkg/repository/repository_unexported_test.go +++ b/src/pkg/repository/repository_unexported_test.go @@ -4,11 +4,11 @@ import ( "context" "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/kopia" "github.com/alcionai/corso/src/internal/model" "github.com/alcionai/corso/src/internal/operations" diff --git a/src/pkg/selectors/exchange_test.go b/src/pkg/selectors/exchange_test.go index b9b95b253..8d1dc3d8a 100644 --- a/src/pkg/selectors/exchange_test.go +++ b/src/pkg/selectors/exchange_test.go @@ -5,11 +5,11 @@ import ( "testing" "time" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/backup/details" diff --git a/src/pkg/selectors/helpers_test.go b/src/pkg/selectors/helpers_test.go index 39add6fb9..35a34750e 100644 --- a/src/pkg/selectors/helpers_test.go +++ b/src/pkg/selectors/helpers_test.go @@ -4,10 +4,10 @@ import ( "strings" "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/pkg/backup/details" "github.com/alcionai/corso/src/pkg/filters" "github.com/alcionai/corso/src/pkg/path" diff --git a/src/pkg/selectors/onedrive_test.go b/src/pkg/selectors/onedrive_test.go index a0f188886..6b0c42f56 100644 --- a/src/pkg/selectors/onedrive_test.go +++ b/src/pkg/selectors/onedrive_test.go @@ -4,11 +4,11 @@ import ( "testing" "time" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/backup/details" diff --git a/src/pkg/selectors/scopes_test.go b/src/pkg/selectors/scopes_test.go index 554dd6307..4f0e68f28 100644 --- a/src/pkg/selectors/scopes_test.go +++ b/src/pkg/selectors/scopes_test.go @@ -3,11 +3,11 @@ package selectors import ( "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/backup/details" "github.com/alcionai/corso/src/pkg/fault" diff --git a/src/pkg/selectors/selectors.go b/src/pkg/selectors/selectors.go index 692491b08..10b56f4e7 100644 --- a/src/pkg/selectors/selectors.go +++ b/src/pkg/selectors/selectors.go @@ -32,9 +32,9 @@ var serviceToPathType = map[service]path.ServiceType{ } var ( - ErrorBadSelectorCast = errors.New("wrong selector service type") - ErrorNoMatchingItems = errors.New("no items match the specified selectors") - ErrorUnrecognizedService = errors.New("unrecognized service") + ErrorBadSelectorCast = clues.New("wrong selector service type") + ErrorNoMatchingItems = clues.New("no items match the specified selectors") + ErrorUnrecognizedService = clues.New("unrecognized service") ) const ( @@ -279,7 +279,7 @@ func selectorAsIface[T any](s Selector) (T, error) { a, err = func() (any, error) { return s.ToSharePointRestore() }() t = a.(T) default: - err = clues.Stack(ErrorUnrecognizedService, errors.New(s.Service.String())) + err = clues.Stack(ErrorUnrecognizedService, clues.New(s.Service.String())) } return t, err diff --git a/src/pkg/selectors/selectors_test.go b/src/pkg/selectors/selectors_test.go index 2fe187b4e..8651d1823 100644 --- a/src/pkg/selectors/selectors_test.go +++ b/src/pkg/selectors/selectors_test.go @@ -3,10 +3,10 @@ package selectors import ( "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/filters" "github.com/alcionai/corso/src/pkg/path" diff --git a/src/pkg/selectors/sharepoint_test.go b/src/pkg/selectors/sharepoint_test.go index bec730956..0e85b4824 100644 --- a/src/pkg/selectors/sharepoint_test.go +++ b/src/pkg/selectors/sharepoint_test.go @@ -4,11 +4,11 @@ import ( "testing" "time" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/backup/details" diff --git a/src/pkg/services/m365/m365.go b/src/pkg/services/m365/m365.go index b53fd047c..e078152cf 100644 --- a/src/pkg/services/m365/m365.go +++ b/src/pkg/services/m365/m365.go @@ -5,7 +5,6 @@ import ( "github.com/alcionai/clues" "github.com/microsoftgraph/msgraph-sdk-go/models" - "github.com/pkg/errors" "github.com/alcionai/corso/src/internal/connector" "github.com/alcionai/corso/src/internal/connector/discovery" @@ -47,7 +46,7 @@ func Users(ctx context.Context, acct account.Account, errs *fault.Bus) ([]*User, for _, u := range users { pu, err := parseUser(u) if err != nil { - return nil, errors.Wrap(err, "parsing userable") + return nil, clues.Wrap(err, "parsing userable") } ret = append(ret, pu) @@ -99,7 +98,7 @@ type Site struct { func Sites(ctx context.Context, acct account.Account, errs *fault.Bus) ([]*Site, error) { gc, err := connector.NewGraphConnector(ctx, graph.HTTPClient(graph.NoTimeout()), acct, connector.Sites, errs) if err != nil { - return nil, errors.Wrap(err, "initializing M365 graph connection") + return nil, clues.Wrap(err, "initializing M365 graph connection") } // gc.Sites is a map with keys: SiteURL, values: ID @@ -118,7 +117,7 @@ func Sites(ctx context.Context, acct account.Account, errs *fault.Bus) ([]*Site, func SiteURLs(ctx context.Context, acct account.Account, errs *fault.Bus) ([]string, error) { gc, err := connector.NewGraphConnector(ctx, graph.HTTPClient(graph.NoTimeout()), acct, connector.Sites, errs) if err != nil { - return nil, errors.Wrap(err, "initializing M365 graph connection") + return nil, clues.Wrap(err, "initializing M365 graph connection") } return gc.GetSiteWebURLs(), nil @@ -128,7 +127,7 @@ func SiteURLs(ctx context.Context, acct account.Account, errs *fault.Bus) ([]str func SiteIDs(ctx context.Context, acct account.Account, errs *fault.Bus) ([]string, error) { gc, err := connector.NewGraphConnector(ctx, graph.HTTPClient(graph.NoTimeout()), acct, connector.Sites, errs) if err != nil { - return nil, errors.Wrap(err, "initializing graph connection") + return nil, clues.Wrap(err, "initializing graph connection") } return gc.GetSiteIDs(), nil diff --git a/src/pkg/services/m365/m365_test.go b/src/pkg/services/m365/m365_test.go index a28b6e1f8..b22f0a37b 100644 --- a/src/pkg/services/m365/m365_test.go +++ b/src/pkg/services/m365/m365_test.go @@ -3,10 +3,10 @@ package m365 import ( "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/fault" ) diff --git a/src/pkg/storage/common.go b/src/pkg/storage/common.go index e230e50fb..06c082b57 100644 --- a/src/pkg/storage/common.go +++ b/src/pkg/storage/common.go @@ -2,7 +2,6 @@ package storage import ( "github.com/alcionai/clues" - "github.com/pkg/errors" "github.com/alcionai/corso/src/pkg/credentials" ) @@ -46,7 +45,7 @@ func (s Storage) CommonConfig() (CommonConfig, error) { // ensures all required properties are present func (c CommonConfig) validate() error { if len(c.CorsoPassphrase) == 0 { - return clues.Stack(errMissingRequired, errors.New(credentials.CorsoPassphrase)) + return clues.Stack(errMissingRequired, clues.New(credentials.CorsoPassphrase)) } // kopiaCfgFilePath is not required diff --git a/src/pkg/storage/common_test.go b/src/pkg/storage/common_test.go index 84937f3b9..42deaf608 100644 --- a/src/pkg/storage/common_test.go +++ b/src/pkg/storage/common_test.go @@ -3,10 +3,10 @@ package storage_test import ( "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/pkg/credentials" "github.com/alcionai/corso/src/pkg/storage" ) diff --git a/src/pkg/storage/s3.go b/src/pkg/storage/s3.go index 78de67ce3..baa497b71 100644 --- a/src/pkg/storage/s3.go +++ b/src/pkg/storage/s3.go @@ -4,7 +4,6 @@ import ( "strconv" "github.com/alcionai/clues" - "github.com/pkg/errors" "github.com/alcionai/corso/src/internal/common" ) @@ -82,7 +81,7 @@ func (c S3Config) validate() error { } for k, v := range check { if len(v) == 0 { - return clues.Stack(errMissingRequired, errors.New(k)) + return clues.Stack(errMissingRequired, clues.New(k)) } } diff --git a/src/pkg/storage/storage.go b/src/pkg/storage/storage.go index 029e29596..e635f9981 100644 --- a/src/pkg/storage/storage.go +++ b/src/pkg/storage/storage.go @@ -1,9 +1,10 @@ package storage import ( - "errors" "fmt" + "github.com/alcionai/clues" + "github.com/alcionai/corso/src/internal/common" ) @@ -17,7 +18,7 @@ const ( // storage parsing errors var ( - errMissingRequired = errors.New("missing required storage configuration") + errMissingRequired = clues.New("missing required storage configuration") ) // envvar consts diff --git a/src/pkg/store/backup.go b/src/pkg/store/backup.go index 0585944d4..85aeb2a8f 100644 --- a/src/pkg/store/backup.go +++ b/src/pkg/store/backup.go @@ -3,7 +3,7 @@ package store import ( "context" - "github.com/pkg/errors" + "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/model" "github.com/alcionai/corso/src/pkg/backup" @@ -42,7 +42,7 @@ func (w Wrapper) GetBackup(ctx context.Context, backupID model.StableID) (*backu err := w.Get(ctx, model.BackupSchema, backupID, &b) if err != nil { - return nil, errors.Wrap(err, "getting backup") + return nil, clues.Wrap(err, "getting backup") } return &b, nil diff --git a/src/pkg/store/backup_test.go b/src/pkg/store/backup_test.go index 722b3d603..c33cd8f58 100644 --- a/src/pkg/store/backup_test.go +++ b/src/pkg/store/backup_test.go @@ -4,12 +4,12 @@ import ( "testing" "time" + "github.com/alcionai/clues" "github.com/google/uuid" "github.com/kopia/kopia/repo/manifest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" - "github.com/alcionai/clues" "github.com/alcionai/corso/src/internal/model" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/backup" diff --git a/src/pkg/store/mock/store_mock.go b/src/pkg/store/mock/store_mock.go index 9e3307977..1e20f0bb9 100644 --- a/src/pkg/store/mock/store_mock.go +++ b/src/pkg/store/mock/store_mock.go @@ -3,8 +3,8 @@ package mock import ( "context" + "github.com/alcionai/clues" "github.com/kopia/kopia/repo/manifest" - "github.com/pkg/errors" "github.com/alcionai/corso/src/internal/model" "github.com/alcionai/corso/src/pkg/backup" @@ -58,7 +58,7 @@ func (mms *MockModelStore) Get( *bm = *mms.backup default: - return errors.Errorf("schema %s not supported by mock Get", s) + return clues.New("schema not supported by mock Get").With("schema", s) } return nil @@ -79,7 +79,7 @@ func (mms *MockModelStore) GetIDsForType( return []*model.BaseModel{&b.BaseModel}, nil } - return nil, errors.Errorf("schema %s not supported by mock GetIDsForType", s) + return nil, clues.New("schema not supported by mock GetIDsForType").With("schema", s) } func (mms *MockModelStore) GetWithModelStoreID( @@ -98,7 +98,7 @@ func (mms *MockModelStore) GetWithModelStoreID( *bm = *mms.backup default: - return errors.Errorf("schema %s not supported by mock GetWithModelStoreID", s) + return clues.New("schema not supported by mock GetWithModelStoreID").With("schema", s) } return nil @@ -115,7 +115,7 @@ func (mms *MockModelStore) Put(ctx context.Context, s model.Schema, m model.Mode mms.backup = bm default: - return errors.Errorf("schema %s not supported by mock Put", s) + return clues.New("schema not supported by mock Put").With("schema", s) } return mms.err @@ -128,7 +128,7 @@ func (mms *MockModelStore) Update(ctx context.Context, s model.Schema, m model.M mms.backup = bm default: - return errors.Errorf("schema %s not supported by mock Update", s) + return clues.New("schema not supported by mock Update").With("schema", s) } return mms.err