nidor1998 / s3sync

Full featured, very fast s3 synchornization CLI tool powered by rust
Apache License 2.0
11 stars 1 forks source link

Enable a pipeline to expose an underlying error #29

Closed drauschenbach closed 2 weeks ago

drauschenbach commented 3 weeks ago

Is your feature request related to a problem? Please describe. I'm using s3sync as a library and invoking a pipeline. After a pipeline failure, I can detect whether the sync failed, but I don't have access to an error message that I can report to an end user.

Describe the solution you'd like Augment Pipeline::has_error() with Pipeline::error() -> Option<some_error>.

Describe alternatives you've considered N/A

Additional context N/A

nidor1998 commented 2 weeks ago

I've implemented a method get_errors_and_consume() -> Option<Vec<Error>> to get the error messages from the pipeline. see 0ed8ffa

I'm not sure if this is the best way to do it, but it works for me.

There are many multi-threaded asynchronous tasks in the pipeline, and there are many errors that can occur simultaneously. So, it returns a vector of errors. But, almost cases, it returns only one error. the following code may be sufficient.

if pipeline.has_error() {
    println!("{:?}", pipeline.get_errors_and_consume().unwrap()[0]);
}

This code print the first error that caught(not occurred) during the pipeline execution.

anyhow::Error does not implement Clone or Copy trait. So this method consumes the vector that pipeline holds.

v1.5.0 release include this feature. https://github.com/nidor1998/s3sync/releases/tag/v1.5.0

drauschenbach commented 2 weeks ago

Got it. Thanks!