diff --git a/fslock.go b/fslock.go index 1a28b82..bb2103b 100644 --- a/fslock.go +++ b/fslock.go @@ -104,7 +104,8 @@ retry: } select { case <-ctx.Done(): - return nil, ctx.Err() + log.Warnf("did not acquire lock: %s", ctx.Err()) + return nil, err case <-ticker.C: goto retry } diff --git a/fslock_test.go b/fslock_test.go index 9e2f091..66710e7 100644 --- a/fslock_test.go +++ b/fslock_test.go @@ -3,7 +3,6 @@ package fslock_test import ( "bufio" "context" - "errors" "os" "os/exec" "path/filepath" @@ -158,6 +157,7 @@ func TestWaitLock(t *testing.T) { someFile = "somefile" permErr = "permission denied" heldErr = "lock is already held by us" + wantErr = "someone else has the lock" ) confdir := t.TempDir() @@ -259,7 +259,11 @@ func TestWaitLock(t *testing.T) { if err == nil { t.Fatalf("parent successfully acquired the lock") } - if !errors.Is(err, context.DeadlineExceeded) { - t.Fatalf("did not get expected error: %s", context.DeadlineExceeded) + pe, ok = err.(*os.PathError) + if !ok { + t.Fatalf("wrong error type %T", err) + } + if got := pe.Error(); !strings.Contains(got, wantErr) { + t.Fatalf("error %q does not contain %q", got, wantErr) } }