oras-project / oras-go

ORAS Go library
https://oras.land
Apache License 2.0
172 stars 94 forks source link

add error type return by oras.Copy #677

Open qweeah opened 8 months ago

qweeah commented 8 months ago

Background oras.Copy is consisted of several different operations. To add more context to the returned error, current implementation is to wrap a description string over the error, e.g. when resolving the source artifact fails, below string will be added to wrap the original error:

https://github.com/oras-project/oras-go/blob/f29607202d5a72ee5325171bf7fc6698ccb4e45f/copy.go#L138

Problem This method imposes below challenges when processing the obtained error: 1) string context are hard to process: taking the above error as an example, it's hard to extract out the added context failed to resolve $srcRef out elegantly from caller side 2) lack information of where the error happens: an error might happens on source target or destination target, it's not reflected in the added context

Solution Adding a structured error type for error returned by oras.Copy like below

type CopyError struct {
    // represents the failing operation, e.g. resolve
    Op string 
    // represents where it fails
    On string // enumerable string, source or dest
    // Inner error
    Err error
}