@@ -856,14 +856,36 @@ func (cloud *CloudProvider) WaitForAttach(ctx context.Context, project string, v
856
856
}
857
857
858
858
func wrapOpErr (name string , opErr * computev1.OperationErrorErrors ) error {
859
+ if opErr == nil {
860
+ return nil
861
+ }
862
+
859
863
if opErr .Code == "UNSUPPORTED_OPERATION" {
860
864
if diskType := pdDiskTypeUnsupportedRegex .FindStringSubmatch (opErr .Message ); diskType != nil {
861
865
return & UnsupportedDiskError {
862
866
DiskType : diskType [1 ],
863
867
}
864
868
}
865
869
}
866
- return fmt .Errorf ("operation %v failed (%v): %v" , name , opErr .Code , opErr .Message )
870
+ grpcErrCode := codeForGCEOpError (* opErr )
871
+ return status .Errorf (grpcErrCode , "operation %v failed (%v): %w" , name , opErr .Code , opErr .Message )
872
+ }
873
+
874
+ // codeForGCEOpError return the grpc error code for the passed in
875
+ // gce operation error.
876
+ func codeForGCEOpError (err computev1.OperationErrorErrors ) codes.Code {
877
+ userErrors := map [string ]codes.Code {
878
+ "RESOURCE_NOT_FOUND" : codes .NotFound ,
879
+ "RESOURCE_ALREADY_EXISTS" : codes .AlreadyExists ,
880
+ "OPERATION_CANCELED_BY_USER" : codes .Aborted ,
881
+ "REGION_QUOTA_EXCEEDED" : codes .ResourceExhausted ,
882
+ "QUOTA_EXCEEDED" : codes .ResourceExhausted ,
883
+ "INVALID_USAGE" : codes .InvalidArgument ,
884
+ }
885
+ if code , ok := userErrors [err .Code ]; ok {
886
+ return code
887
+ }
888
+ return codes .Internal
867
889
}
868
890
869
891
func opIsDone (op * computev1.Operation ) (bool , error ) {
0 commit comments