Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: common/gcloud/gs/gs.go

Issue 2951393002: [errors] de-specialize Transient in favor of Tags. (Closed)
Patch Set: copyright Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package gs 5 package gs
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "io" 9 "io"
10 "net/http" 10 "net/http"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 // First stage: CopyTo 134 // First stage: CopyTo
135 err = retry.Retry(c, retry.TransientOnly(retry.Default), func() error { 135 err = retry.Retry(c, retry.TransientOnly(retry.Default), func() error {
136 if _, err := dstObj.CopierFrom(srcObj).Run(c); err != nil { 136 if _, err := dstObj.CopierFrom(srcObj).Run(c); err != nil {
137 // The storage library doesn't return gs.ErrObjectNotExi st when Delete 137 // The storage library doesn't return gs.ErrObjectNotExi st when Delete
138 // returns a 404. Catch that explicitly. 138 // returns a 404. Catch that explicitly.
139 if isNotFoundError(err) { 139 if isNotFoundError(err) {
140 return err 140 return err
141 } 141 }
142 142
143 // Assume all unexpected errors are transient. 143 // Assume all unexpected errors are transient.
144 » » » return errors.WrapTransient(err) 144 » » » return retry.Tag.Apply(err)
145 } 145 }
146 return nil 146 return nil
147 }, func(err error, d time.Duration) { 147 }, func(err error, d time.Duration) {
148 log.Fields{ 148 log.Fields{
149 log.ErrorKey: err, 149 log.ErrorKey: err,
150 "delay": d, 150 "delay": d,
151 "src": src, 151 "src": src,
152 "dst": dst, 152 "dst": dst,
153 }.Warningf(c, "Transient error copying GS file. Retrying...") 153 }.Warningf(c, "Transient error copying GS file. Retrying...")
154 }) 154 })
(...skipping 24 matching lines...) Expand all
179 return retry.Retry(c, retry.TransientOnly(retry.Default), func() error { 179 return retry.Retry(c, retry.TransientOnly(retry.Default), func() error {
180 if err := o.Delete(c); err != nil { 180 if err := o.Delete(c); err != nil {
181 // The storage library doesn't return gs.ErrObjectNotExi st when Delete 181 // The storage library doesn't return gs.ErrObjectNotExi st when Delete
182 // returns a 404. Catch that explicitly. 182 // returns a 404. Catch that explicitly.
183 if isNotFoundError(err) { 183 if isNotFoundError(err) {
184 // If the file wasn't found, then the delete "su cceeded". 184 // If the file wasn't found, then the delete "su cceeded".
185 return nil 185 return nil
186 } 186 }
187 187
188 // Assume all unexpected errors are transient. 188 // Assume all unexpected errors are transient.
189 » » » return errors.WrapTransient(err) 189 » » » return retry.Tag.Apply(err)
190 } 190 }
191 return nil 191 return nil
192 }, func(err error, d time.Duration) { 192 }, func(err error, d time.Duration) {
193 log.Fields{ 193 log.Fields{
194 log.ErrorKey: err, 194 log.ErrorKey: err,
195 "delay": d, 195 "delay": d,
196 }.Warningf(c, "Transient error deleting file. Retrying...") 196 }.Warningf(c, "Transient error deleting file. Retrying...")
197 }) 197 })
198 } 198 }
199 199
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 // The storage library doesn't return gs.ErrObjectNotExist when Delete 231 // The storage library doesn't return gs.ErrObjectNotExist when Delete
232 // returns a 404. Catch that explicitly. 232 // returns a 404. Catch that explicitly.
233 if t, ok := err.(*googleapi.Error); ok { 233 if t, ok := err.(*googleapi.Error); ok {
234 switch t.Code { 234 switch t.Code {
235 case http.StatusNotFound: 235 case http.StatusNotFound:
236 return true 236 return true
237 } 237 }
238 } 238 }
239 return false 239 return false
240 } 240 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698