Skip to content

Commit 440c622

Browse files
committed
Improve lock warning message with clearer action guidance
Make the warning message more actionable by explicitly instructing users what to check and what to do if the lock is stale. The message now tells users to verify if the locking process is still running and provides the exact command needed to resolve the issue (delete the lock file). Signed-off-by: sabine <[email protected]>
1 parent 4e68f7b commit 440c622

File tree

1 file changed

+42
-22
lines changed

1 file changed

+42
-22
lines changed

src/dune_util/global_lock.ml

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,24 @@ let lock ~timeout =
105105
| `Failure ->
106106
let lock_held_by = Lock_held_by.read_lock_file () in
107107
User_warning.emit
108-
[ Pp.textf
109-
"Build directory is locked by another dune process%s. Waiting for the \
110-
lock to be released... (lock file: %s)"
111-
(match lock_held_by with
112-
| Unknown -> ""
113-
| Pid_from_lockfile pid -> sprintf " (pid: %d)" pid)
114-
(Path.Build.to_string lock_file)
115-
];
108+
([ Pp.textf
109+
"Build directory is locked by another dune process%s. Waiting for the \
110+
lock to be released..."
111+
(match lock_held_by with
112+
| Unknown -> ""
113+
| Pid_from_lockfile pid -> sprintf " (pid: %d)" pid)
114+
]
115+
@ (match lock_held_by with
116+
| Pid_from_lockfile _ ->
117+
[ Pp.textf
118+
"If this process is no longer running, delete the lock file: %s"
119+
(Path.Build.to_string lock_file)
120+
]
121+
| Unknown ->
122+
[ Pp.textf
123+
"If no other dune process is running, delete the lock file: %s"
124+
(Path.Build.to_string lock_file)
125+
]));
116126
`Failure)
117127
| Some timeout ->
118128
let warned = ref false in
@@ -121,20 +131,30 @@ let lock ~timeout =
121131
match Lock.lock () with
122132
| `Success -> `Stop
123133
| `Failure ->
124-
if not !warned
125-
then (
126-
warned := true;
127-
let lock_held_by = Lock_held_by.read_lock_file () in
128-
User_warning.emit
129-
[ Pp.textf
130-
"Build directory is locked by another dune process%s. Waiting for \
131-
the lock to be released... (lock file: %s)"
132-
(match lock_held_by with
133-
| Unknown -> ""
134-
| Pid_from_lockfile pid -> sprintf " (pid: %d)" pid)
135-
(Path.Build.to_string lock_file)
136-
]);
137-
`Continue)
134+
if not !warned
135+
then (
136+
warned := true;
137+
let lock_held_by = Lock_held_by.read_lock_file () in
138+
User_warning.emit
139+
([ Pp.textf
140+
"Build directory is locked by another dune process%s. Waiting for \
141+
the lock to be released..."
142+
(match lock_held_by with
143+
| Unknown -> ""
144+
| Pid_from_lockfile pid -> sprintf " (pid: %d)" pid)
145+
]
146+
@ (match lock_held_by with
147+
| Pid_from_lockfile _ ->
148+
[ Pp.textf
149+
"If this process is no longer running, delete the lock file: %s"
150+
(Path.Build.to_string lock_file)
151+
]
152+
| Unknown ->
153+
[ Pp.textf
154+
"If no other dune process is running, delete the lock file: %s"
155+
(Path.Build.to_string lock_file)
156+
])));
157+
`Continue)
138158
with
139159
| `Timed_out -> `Failure
140160
| `Success -> `Success)

0 commit comments

Comments
 (0)