Skip to content

Commit

Permalink
better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
fenio committed Oct 25, 2024
1 parent 1d65663 commit 9c3ab1b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cmd/plugin/cli/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cli

import (
"context"
"log"
"fmt"

"github.com/fenio/pv-mounter/pkg/plugin"
"github.com/spf13/cobra"
Expand All @@ -22,7 +22,7 @@ func cleanCmd() *cobra.Command {
ctx := context.Background()

if err := plugin.Clean(ctx, namespace, pvcName, localMountPoint); err != nil {
log.Fatalf("Failed to clean PVC: %v", err)
return fmt.Errorf("failed to clean PVC: %w", err)
}
return nil
},
Expand Down
8 changes: 4 additions & 4 deletions cmd/plugin/cli/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cli

import (
"context"
"log"
"fmt"
"os"
"strconv"

Expand All @@ -25,7 +25,7 @@ func mountCmd() *cobra.Command {
if parsedNeedsRoot, err := strconv.ParseBool(needsRootEnv); err == nil {
needsRoot = parsedNeedsRoot
} else {
log.Fatalf("Invalid value for NEEDS_ROOT: %v", needsRootEnv)
return fmt.Errorf("invalid value for NEEDS_ROOT: %v", needsRootEnv)
}
}

Expand All @@ -35,7 +35,7 @@ func mountCmd() *cobra.Command {
if parsedDebug, err := strconv.ParseBool(debugEnv); err == nil {
debug = parsedDebug
} else {
log.Fatalf("Invalid value for DEBUG: %v", debugEnv)
return fmt.Errorf("invalid value for DEBUG: %v", debugEnv)
}
}

Expand All @@ -47,7 +47,7 @@ func mountCmd() *cobra.Command {
ctx := context.Background()

if err := plugin.Mount(ctx, namespace, pvcName, localMountPoint, needsRoot, debug); err != nil {
log.Fatalf("Failed to mount PVC: %v", err)
return fmt.Errorf("failed to mount PVC: %w", err)
}
return nil
},
Expand Down

0 comments on commit 9c3ab1b

Please sign in to comment.