diff --git a/src/cli/backup/exchange.go b/src/cli/backup/exchange.go index b993a335b..de3e37f3c 100644 --- a/src/cli/backup/exchange.go +++ b/src/cli/backup/exchange.go @@ -36,7 +36,7 @@ func addExchangeCommands(parent *cobra.Command) *cobra.Command { case detailsCommand: c, fs = utils.AddCommand(parent, exchangeDetailsCmd) fs.StringVar(&backupDetailsID, "backup-details", "", "ID of the backup details to be shown.") - c.MarkFlagRequired("backup-details") + cobra.CheckErr(c.MarkFlagRequired("backup-details")) } return c } diff --git a/src/cli/cli.go b/src/cli/cli.go index f2a47249f..79a11ce84 100644 --- a/src/cli/cli.go +++ b/src/cli/cli.go @@ -65,7 +65,9 @@ func Handle() { restore.AddCommands(corsoCmd) ctx, log := logger.Seed(context.Background()) - defer log.Sync() // flush all logs in the buffer + defer func() { + _ = log.Sync() // flush all logs in the buffer + }() if err := corsoCmd.ExecuteContext(ctx); err != nil { fmt.Println(err) diff --git a/src/cli/repo/repo.go b/src/cli/repo/repo.go index 6836344ab..ff431a364 100644 --- a/src/cli/repo/repo.go +++ b/src/cli/repo/repo.go @@ -26,14 +26,14 @@ var repoCmd = &cobra.Command{ Use: "repo", Short: "Manage your repositories", Long: `Initialize, configure, and connect to your account backup repositories.`, - Run: handleRepoCmd, + RunE: handleRepoCmd, Args: cobra.NoArgs, } // Handler for flat calls to `corso repo`. // Produces the same output as `corso repo --help`. -func handleRepoCmd(cmd *cobra.Command, args []string) { - cmd.Help() +func handleRepoCmd(cmd *cobra.Command, args []string) error { + return cmd.Help() } // The repo init subcommand. diff --git a/src/cli/repo/s3.go b/src/cli/repo/s3.go index d7389379d..2baa7f52f 100644 --- a/src/cli/repo/s3.go +++ b/src/cli/repo/s3.go @@ -38,7 +38,7 @@ func addS3Commands(parent *cobra.Command) *cobra.Command { } fs.StringVar(&accessKey, "access-key", "", "Access key ID (replaces the AWS_ACCESS_KEY_ID env variable).") fs.StringVar(&bucket, "bucket", "", "Name of the S3 bucket (required).") - c.MarkFlagRequired("bucket") + cobra.CheckErr(c.MarkFlagRequired("bucket")) fs.StringVar(&endpoint, "endpoint", "s3.amazonaws.com", "Server endpoint for S3 communication.") fs.StringVar(&prefix, "prefix", "", "Prefix applied to objects in the bucket.") return c diff --git a/src/cli/restore/exchange.go b/src/cli/restore/exchange.go index 6e41c84dd..396364c48 100644 --- a/src/cli/restore/exchange.go +++ b/src/cli/restore/exchange.go @@ -34,7 +34,7 @@ func addExchangeCommands(parent *cobra.Command) *cobra.Command { fs.StringVar(&folder, "folder", "", "Name of the mail folder being restored") fs.StringVar(&mail, "mail", "", "ID of the mail message being restored") fs.StringVar(&backupID, "backup", "", "ID of the backup to restore") - c.MarkFlagRequired("backup") + cobra.CheckErr(c.MarkFlagRequired("backup")) fs.StringVar(&user, "user", "", "ID of the user whose exchange data will get restored") } return c diff --git a/src/cli/restore/restore.go b/src/cli/restore/restore.go index 6d5b6d583..53eeb9ec9 100644 --- a/src/cli/restore/restore.go +++ b/src/cli/restore/restore.go @@ -25,12 +25,12 @@ var restoreCmd = &cobra.Command{ Use: restoreCommand, Short: "Restore your service data", Long: `Restore the data stored in one of your M365 services.`, - Run: handleRestoreCmd, + RunE: handleRestoreCmd, Args: cobra.NoArgs, } // Handler for flat calls to `corso restore`. // Produces the same output as `corso restore --help`. -func handleRestoreCmd(cmd *cobra.Command, args []string) { - cmd.Help() +func handleRestoreCmd(cmd *cobra.Command, args []string) error { + return cmd.Help() } diff --git a/src/cli/utils/utils.go b/src/cli/utils/utils.go index 9e7c51acb..9a07f891d 100644 --- a/src/cli/utils/utils.go +++ b/src/cli/utils/utils.go @@ -35,7 +35,7 @@ func CloseRepo(ctx context.Context, r *repository.Repository) { // (ex: corso backup restore exchange) is expected to no-op. func HasNoFlagsAndShownHelp(cmd *cobra.Command) bool { if cmd.Flags().NFlag() == 0 { - cmd.Help() + cobra.CheckErr(cmd.Help()) return true } return false diff --git a/src/internal/kopia/conn_test.go b/src/internal/kopia/conn_test.go index 6c41c86eb..47ccb1f3a 100644 --- a/src/internal/kopia/conn_test.go +++ b/src/internal/kopia/conn_test.go @@ -86,7 +86,7 @@ func (suite *WrapperIntegrationSuite) TestCloseAfterWrap() { k, err := openKopiaRepo(t, ctx) require.NoError(t, err) - k.wrap() + require.NoError(t, k.wrap()) assert.Equal(t, 2, k.refCount) diff --git a/src/internal/testing/envvars_test.go b/src/internal/testing/envvars_test.go index 1e48774a5..e7edda515 100644 --- a/src/internal/testing/envvars_test.go +++ b/src/internal/testing/envvars_test.go @@ -16,7 +16,7 @@ func TestEnvvarsSuite(t *testing.T) { suite.Run(t, new(EnvvarsTestSuite)) } -func (suite EnvvarsTestSuite) TestRunOnAny() { +func (suite *EnvvarsTestSuite) TestRunOnAny() { env_variable := "TEST_ENVVARS_SUITE" os.Setenv(env_variable, "1") table := []struct {