Skip to content

Commit c7de429

Browse files
Kenoclaude
authored andcommitted
Improve error message for missing paths in mount operations
When mount() fails with ENOENT (No such file or directory), provide a descriptive error message that includes: - Source and destination paths in the error message - System error description (strerror) and errno - Helpful hint about checking source path existence All other mount failures continue to use the generic check() assertion as before, preserving the original error handling behavior for non-ENOENT errors. This makes debugging missing path issues much easier while maintaining the existing error handling for other failure cases. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6460160 commit c7de429

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

deps/userns_common.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,15 @@ void bind_mount(const char *src, const char *dest, char read_only) {
299299
// We don't expect workspaces to have any submounts in normal operation.
300300
// However, for runshell(), workspace could be an arbitrary directory,
301301
// including one with sub-mounts, so allow that situation with MS_REC.
302-
check(0 == mount(resolved_src, dest, "", MS_BIND|MS_REC, NULL));
302+
int mount_result = mount(resolved_src, dest, "", MS_BIND|MS_REC, NULL);
303+
if (mount_result != 0 && errno == ENOENT) {
304+
// Provide a more descriptive error for missing paths
305+
fprintf(stderr, "ERROR: Failed to mount '%s' to '%s': %s (errno %d)\n",
306+
resolved_src, dest, strerror(errno), errno);
307+
fprintf(stderr, " Please ensure that '%s' exists and is accessible.\n", resolved_src);
308+
_exit(1);
309+
}
310+
check(mount_result == 0);
303311

304312
// remount to read-only. this requires a separate remount:
305313
// https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/commit/?id=9ac77b8a78452eab0612523d27fee52159f5016a

0 commit comments

Comments
 (0)