From e2d9ae071c820c62a5ee3884d76ab6a670707446 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 7 Apr 2026 11:29:04 -0700 Subject: [PATCH] shell: distinguish NotFound from transient errors in provision, use %w wrapping MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - s3.user.provision: check gRPC status code on GetUser error — only proceed on NotFound, abort on transient/network errors - s3.iam.import: use %w for error wrapping to preserve error chains, wrap PutConfiguration error with context --- weed/shell/command_s3_iam_import.go | 6 +++--- weed/shell/command_s3_user_provision.go | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/weed/shell/command_s3_iam_import.go b/weed/shell/command_s3_iam_import.go index c27d64cc1..1b47f528e 100644 --- a/weed/shell/command_s3_iam_import.go +++ b/weed/shell/command_s3_iam_import.go @@ -58,12 +58,12 @@ func (c *commandS3IAMImport) Do(args []string, commandEnv *CommandEnv, writer io data, err := os.ReadFile(*file) if err != nil { - return fmt.Errorf("read file: %v", err) + return fmt.Errorf("read file: %w", err) } config := &iam_pb.S3ApiConfiguration{} if err := filer.ParseS3ConfigurationFromBytes(data, config); err != nil { - return fmt.Errorf("parse configuration: %v", err) + return fmt.Errorf("parse configuration: %w", err) } err = pb.WithGrpcClient(false, 0, func(conn *grpc.ClientConn) error { @@ -76,7 +76,7 @@ func (c *commandS3IAMImport) Do(args []string, commandEnv *CommandEnv, writer io return err }, commandEnv.option.FilerAddress.ToGrpcAddress(), false, commandEnv.option.GrpcDialOption) if err != nil { - return err + return fmt.Errorf("put IAM configuration: %w", err) } fmt.Fprintf(writer, "Imported IAM configuration from %s\n", *file) diff --git a/weed/shell/command_s3_user_provision.go b/weed/shell/command_s3_user_provision.go index 9c16719bb..397c07ed7 100644 --- a/weed/shell/command_s3_user_provision.go +++ b/weed/shell/command_s3_user_provision.go @@ -13,6 +13,8 @@ import ( "github.com/seaweedfs/seaweedfs/weed/pb" "github.com/seaweedfs/seaweedfs/weed/pb/iam_pb" "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" ) func init() { @@ -126,6 +128,8 @@ func (c *commandS3UserProvision) Do(args []string, commandEnv *CommandEnv, write // Step 0: Check if user already exists if resp, getErr := client.GetUser(ctx, &iam_pb.GetUserRequest{Username: *name}); getErr == nil && resp.Identity != nil { return fmt.Errorf("user %q already exists", *name) + } else if getErr != nil && status.Code(getErr) != codes.NotFound { + return fmt.Errorf("check user existence: %w", getErr) } // Step 1: Create policy