Skip to content

Commit

Permalink
Merge pull request Homebrew#16462 from MikeMcQuaid/improve_pwd_messages
Browse files Browse the repository at this point in the history
Improve working directory error messages
  • Loading branch information
MikeMcQuaid authored Jan 11, 2024
2 parents 6a19bcb + abc1d14 commit 3e537a2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 6 additions & 2 deletions Library/Homebrew/brew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,13 @@ fi

# Many Pathname operations use getwd when they shouldn't, and then throw
# odd exceptions. Reduce our support burden by showing a user-friendly error.
if [[ ! -d "$(pwd)" ]]
if ! [[ -d "$(pwd)" ]]
then
odie "The current working directory doesn't exist, cannot proceed."
odie "The current working directory must exist to run brew."
fi
if ! [[ -r "$(pwd)" ]]
then
odie "The current working directory must be readable to run brew."
fi

#####
Expand Down
14 changes: 12 additions & 2 deletions bin/brew
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@ fi

set +o posix # as we are using bash now

# Fail fast with concise message when cwd does not exist
# Fail fast with concise messages when PWD has issues
if [[ -z "${PWD-}" ]]
then
echo "Error: \$PWD must be set to run brew." >&2
exit 1
fi
if ! [[ -d "${PWD}" ]]
then
echo "Error: The current working directory doesn't exist, cannot proceed." >&2
echo "Error: The current working directory must exist to run brew." >&2
exit 1
fi
if ! [[ -r "${PWD}" ]]
then
echo "Error: The current working directory must be readable to run brew." >&2
exit 1
fi

Expand Down

0 comments on commit 3e537a2

Please sign in to comment.