@@ -42,10 +42,20 @@ const (
4242// cobraRunEFunc is the signature of a cobra.Command.RunE function.
4343type cobraRunEFunc = func (cmd * cobra.Command , args []string ) (err error )
4444
45+ // TODO: apply these to other cmds as well
46+ var errorHandlers = []func (error ) error {
47+ addPermissionDeniedErrInfo ,
48+ addSizeErrInfo ,
49+ }
50+
4551// withErrorHandling is a wrapper that centralizes error handling, instead of having to scatter it around the command logic.
4652func withErrorHandling (f cobraRunEFunc ) cobraRunEFunc {
4753 return func (cmd * cobra.Command , args []string ) (err error ) {
48- return addSizeErrInfo (f (cmd , args ))
54+ cmdErr := f (cmd , args )
55+ for _ , handler := range errorHandlers {
56+ cmdErr = handler (cmdErr )
57+ }
58+ return cmdErr
4959 }
5060}
5161
@@ -398,9 +408,15 @@ func backupCreateCmdFunc(cmd *cobra.Command, args []string) (err error) {
398408 }
399409 return nil
400410 })
411+ if err != nil {
412+ return err
413+ }
401414
402415 backupCompleted = true
403- return nil
416+ // NOTE: we return err here because there's cleanup being done
417+ // in the `defer` blocks that will modify the `err` if cleanup
418+ // fails
419+ return err
404420}
405421
406422func takeBackup (ctx context.Context , spiceClient client.Client , req * v1.ExportBulkRelationshipsRequest , processResponse func (* v1.ExportBulkRelationshipsResponse ) error ) error {
@@ -902,3 +918,15 @@ func addSizeErrInfo(err error) error {
902918
903919 return fmt .Errorf ("%w: set flag --max-message-size=%d to increase the maximum allowable size" , err , 2 * necessaryByteCount )
904920}
921+
922+ func addPermissionDeniedErrInfo (err error ) error {
923+ if err == nil {
924+ return nil
925+ }
926+
927+ code := status .Code (err )
928+ if code != codes .PermissionDenied {
929+ return err
930+ }
931+ return fmt .Errorf ("%w: ensure that the token used for this call has all requisite permissions" , err )
932+ }
0 commit comments