diff --git a/all_test.go b/all_test.go index f5348ef..8a36ceb 100644 --- a/all_test.go +++ b/all_test.go @@ -378,6 +378,16 @@ func TestOptions_OnFileError(t *testing.T) { _, err = os.Stat("test/data.copy/case17/non-existing") Expect(t, os.IsNotExist(err)).ToBe(true) + // existing, err not passed + var called bool + opt.OnErr = func(err error) error { + called = true + return err + } + err = Copy("test/data/case17", "test/data.copy/case17", opt) + Expect(t, err).ToBe(nil) + Expect(t, called).ToBe(false) + // not existing, process err opt.OnErr = func(err error) error { return err } err = Copy("test/data/case17/non-existing", "test/data.copy/case17/non-existing", opt) diff --git a/copy.go b/copy.go index b72f35a..84bdfba 100644 --- a/copy.go +++ b/copy.go @@ -242,6 +242,9 @@ func fclose(f *os.File, reported *error) { // onError lets caller to handle errors // occured when copying a file. func onError(err error, opt Options) error { + if err == nil { + return nil + } if opt.OnErr == nil { return err }