@@ -250,13 +250,9 @@ func (b *Backend) List(ctx context.Context, prefix string) (blobList simpleblob.
250250 // So we're using the raw marker name here.
251251 m , err := b .Load (ctx , UpdateMarkerFilename )
252252
253- var notFound bool
253+ notFound := errors . Is ( err , os . ErrNotExist )
254254
255- if err != nil {
256- notFound = bloberror .HasCode (err , bloberror .BlobNotFound )
257- }
258-
259- if err != nil && notFound {
255+ if err != nil && ! notFound {
260256 return nil , err
261257 }
262258
@@ -288,6 +284,23 @@ func (b *Backend) List(ctx context.Context, prefix string) (blobList simpleblob.
288284 return blobs .WithPrefix (prefix ), nil
289285}
290286
287+ // convertAzureError takes an error from Azure SDK and converts it to
288+ // os.ErrNotExist when appropriate (BlobNotFound, ContainerNotFound, ResourceNotFound).
289+ // If the error is not a "not found" error, it is returned as is.
290+ func convertAzureError (err error ) error {
291+ if err == nil {
292+ return nil
293+ }
294+ if bloberror .HasCode (err ,
295+ bloberror .BlobNotFound ,
296+ bloberror .ContainerNotFound ,
297+ bloberror .ResourceNotFound ,
298+ ) {
299+ return fmt .Errorf ("%w: %s" , os .ErrNotExist , err .Error ())
300+ }
301+ return err
302+ }
303+
291304func (b * Backend ) doList (ctx context.Context , prefix string ) (simpleblob.BlobList , error ) {
292305 var blobs simpleblob.BlobList
293306
@@ -364,7 +377,8 @@ func (b *Backend) doLoadReader(ctx context.Context, name string) (io.ReadCloser,
364377
365378 // Download the blob's contents and ensure that the download worked properly
366379 blobDownloadResponse , err := b .client .DownloadStream (ctx , b .opt .Container , name , nil )
367- if err != nil {
380+ if err = convertAzureError (err ); err != nil {
381+ metricCallErrors .WithLabelValues ("load" ).Inc ()
368382 return nil , err
369383 }
370384
@@ -435,12 +449,16 @@ func (b *Backend) doDelete(ctx context.Context, name string) error {
435449
436450 _ , err := b .client .DeleteBlob (ctx , b .opt .Container , name , nil )
437451
438- if err != nil {
452+ if err = convertAzureError (err ); err != nil {
453+ // Delete is idempotent - if blob doesn't exist, that's fine
454+ if errors .Is (err , os .ErrNotExist ) {
455+ return nil
456+ }
439457 metricCallErrors .WithLabelValues ("delete" ).Inc ()
440458 return err
441459 }
442460
443- return err
461+ return nil
444462}
445463
446464// setGlobalPrefix updates the global prefix in b and the cached marker name,
0 commit comments