@@ -45,10 +45,6 @@ func IsImageNotFoundErr(err error) bool {
4545 return false
4646 }
4747
48- if ! isErrImage (err ) {
49- return false
50- }
51-
5248 if isMaskedHTTP404 (err ) {
5349 return true
5450 }
@@ -68,10 +64,6 @@ func IsAccessDeniedErr(err error) bool {
6864 return false
6965 }
7066
71- if ! isErrImage (err ) {
72- return false
73- }
74-
7567 if isAccessDeniedErrorCode (err ) {
7668 return true
7769 }
@@ -225,61 +217,35 @@ func isTolerableUnexpectedHTTPStatusError(err error) bool {
225217
226218// ErrImage holds and wraps an error related to a specific image.
227219type ErrImage struct {
228- msg string
229- img string
230- err error
231- }
232-
233- // newErrImageWithMessage constructs a new ErrImage instance with a custom message,
234- // image pullspec, and wrapped error.
235- func newErrImageWithMessage (msg , img string , err error ) error {
236- return & ErrImage {msg : msg , img : img , err : err }
220+ image string
221+ err error
237222}
238223
239224// newErrImage constructs a new ErrImage instance with an image pullspec and
240- // wrapped error, without a custom message .
225+ // wrapped error.
241226func newErrImage (img string , err error ) error {
242- return & ErrImage {img : img , err : err }
227+ return & ErrImage {image : img , err : err }
243228}
244229
245- // Image returns the image pullspec that caused the error .
230+ // Returns the image embedded within the ErrImage struct .
246231func (e * ErrImage ) Image () string {
247- return e .img
232+ return e .image
248233}
249234
250235// Error implements the error interface, providing a formatted error string
251- // including the message (if present), image (if present), and the wrapped error's string.
236+ // including the image (if present), and the wrapped error's string.
252237func (e * ErrImage ) Error () string {
253- if e . msg != "" && e . img != "" {
254- // If both the message and image are not empty, include both.
255- return fmt .Sprintf ("%s: image %q: %s" , e .msg , e . img , e .err .Error ())
238+ // If the image is defined and not contained within the underlying error, inject it here.
239+ if e . image != "" && ! strings . Contains ( e . err . Error (), e . image ) {
240+ return fmt .Sprintf ("error occurred with image %q: %s" , e .image , e .err .Error ())
256241 }
257242
258- if e .msg == "" && e .img != "" {
259- // If the message is empty and the image is not, only include the image.
260- return fmt .Sprintf ("image %q: %s" , e .img , e .err .Error ())
261- }
262-
263- // If neither the message nor the image is populated, just return the error
264- // string as-is.
243+ // If the image is undefined or is already present in the error, return the
244+ // error as-is.
265245 return e .err .Error ()
266246}
267247
268248// Unwrap implements the Unwrap interface, allowing the nested error to be surfaced.
269249func (e * ErrImage ) Unwrap () error {
270250 return e .err
271251}
272-
273- // isErrImage determines whether the given error is an instance of the ErrImage
274- // type defined above.
275- func isErrImage (err error ) bool {
276- if err == nil {
277- return false
278- }
279-
280- // Any errors related to the actual image registry query are wrapped in an
281- // ErrImage instance. This allows us to easily identify intolerable errors
282- // such as not being able to write the authfile or certs, etc.
283- var errImage * ErrImage
284- return errors .As (err , & errImage )
285- }
0 commit comments