Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmd/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ type errorMessage struct {
SysInfo map[string]string `json:"sysinfo,omitempty"`
}

// errorOrFatal wrapper function to call errorIf or fatalIf based on the boolean value
func errorOrFatal(useFatal bool, err *probe.Error, msg string, data ...interface{}) {
if useFatal {
fatalIf(err, msg, data...)
}
errorIf(err, msg, data...)
}

// fatalIf wrapper function which takes error and selectively prints stack frames if available on debug
func fatalIf(err *probe.Error, msg string, data ...interface{}) {
if err == nil {
Expand Down
13 changes: 9 additions & 4 deletions cmd/mirror-main.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,10 @@ func (mj *mirrorJob) monitorMirrorStatus(cancel context.CancelFunc) (errDuringMi
mj.status.Start()
defer mj.status.Finish()

// if the operation is not retriable and fail-on-error is true, then
// we should exit on the first error.
useFatal := mj.opts.failOnError && !mj.opts.isRetriable

var cancelInProgress bool

defer func() {
Expand Down Expand Up @@ -595,22 +599,22 @@ func (mj *mirrorJob) monitorMirrorStatus(cancel context.CancelFunc) (errDuringMi
ignoreErr = true
}
if !ignoreErr {
errorIf(sURLs.Error.Trace(sURLs.SourceContent.URL.String()),
errorOrFatal(useFatal, sURLs.Error.Trace(sURLs.SourceContent.URL.String()),
"Failed to copy `%s`.", sURLs.SourceContent.URL)
}
}
case sURLs.TargetContent != nil:
// When sURLs.SourceContent is nil, we know that we have an error related to removing
errorIf(sURLs.Error.Trace(sURLs.TargetContent.URL.String()),
errorOrFatal(useFatal, sURLs.Error.Trace(sURLs.TargetContent.URL.String()),
"Failed to remove `%s`.", sURLs.TargetContent.URL.String())
default:
if strings.Contains(sURLs.Error.ToGoError().Error(), "Overwrite not allowed") {
ignoreErr = true
}
if sURLs.ErrorCond == differInUnknown {
errorIf(sURLs.Error.Trace(), "Failed to perform mirroring")
errorOrFatal(useFatal, sURLs.Error.Trace(), "Failed to perform mirroring")
} else {
errorIf(sURLs.Error.Trace(),
errorOrFatal(useFatal, sURLs.Error.Trace(),
"Failed to perform mirroring, with error condition (%s)", sURLs.ErrorCond)
}
}
Expand Down Expand Up @@ -1011,6 +1015,7 @@ func runMirror(ctx context.Context, srcURL, dstURL string, cli *cli.Context, enc
isMetadata: isMetadata,
isSummary: cli.Bool("summary"),
isRetriable: cli.Bool("retry"),
failOnError: cli.Bool("fail-on-error"),
Comment thread
klauspost marked this conversation as resolved.
md5: md5,
checksum: checksum,
disableMultipart: cli.Bool("disable-multipart"),
Expand Down
1 change: 1 addition & 0 deletions cmd/mirror-url.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ type mirrorOptions struct {
isFake, isOverwrite, activeActive bool
isWatch, isRemove, isMetadata bool
isRetriable bool
failOnError bool
isSummary bool
skipErrors bool
excludeOptions, excludeStorageClasses, excludeBuckets []string
Expand Down