Skip to content

Include lock file path in locking error messages - #57

Merged
gaborcsardi merged 4 commits into
r-lib:mainfrom
SzarR:lock-error-paths
Sep 24, 2026
Merged

gaborcsardi merged 4 commits into
r-lib:mainfrom
SzarR:lock-error-paths

Conversation

@SzarR

@SzarR SzarR commented Sep 17, 2026 •

Copy link
Copy Markdown

Problem

When locking fails, the error message does not say which lock file could not be opened or locked. This makes stale lock files (e.g. left behind by an interrupted pak::pkg_install(), see r-lib/pak#263) hard for users to find and remove.

Changes

All locking error messages now include the lock file path, in backticks, and follow the tidyverse error style ("Can't", trailing full stop), within the constraints of raising errors from C without a cli dependency:

  • Unix: Can't open lock file `<path>`: Permission denied. (and similarly for lock failures).
  • Windows: filelock__error() now formats Can't open lock file `<path>`: Access is denied (Windows error 5)., putting the problem statement before the error code and stripping the trailing CRLF of the system message.
  • The File `<path>` already has a shared/exclusive lock. errors now name the file.
  • Fixed the utf8.c caller of filelock__error() for the new signature.
  • Added a regression test asserting the path appears in the error message when the lock file cannot be opened, and updated the snapshot test (with a path-scrubbing transform) for the new messages.
  • NEWS entry.

Note: I could only compile and test the Unix implementation locally (macOS); the Windows code paths should be verified by CI.

Closes #30.

Robert Szarek and others added 4 commits September 17, 2026 13:25
Errors raised when opening or locking a lock file fails now name the
file, so users can find and remove stale lock files.

Closes r-lib#30.
- Use "Can't", backticks around file paths, and trailing full stops.
- The 'already has a shared/exclusive lock' errors now name the file.
- Fix utf8.c to the new filelock__error() signature; it would not
  have compiled on Windows otherwise.
- Strip the trailing CRLF of Windows system error messages.

Ref r-lib#30.
lock() reports the path as file.path(normalizePath(dirname), basename),
which mixes path separators on Windows, so scrub that exact string.

Ref r-lib#30.
@gaborcsardi
gaborcsardi merged commit 7078297 into r-lib:main Sep 24, 2026
13 checks passed
@gaborcsardi

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Print lock file path on locking error

2 participants