Skip to content

Commit

Permalink
nil err check
Browse files Browse the repository at this point in the history
  • Loading branch information
michalpristas committed Apr 3, 2023
1 parent a731943 commit 816a705
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 816a705

Please sign in to comment.