Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error handling #12

Merged
merged 2 commits into from
Mar 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,19 @@ sandbox () {
# Resume or initialize sandbox
if [[ -d data ]]; then
statusline "Starting the existing sandbox..."
set +e
docker start sandbox > /dev/null
# Use variable $ERROR instead of status $?
# as we are using set -e which aborts in case of non-zero status
ERROR=0
docker start sandbox > /dev/null || ERROR=1

if [[ $ERROR -ne 0 ]]; then
# Check if the error is not just due to docker daemon not running
if ! docker info 2>/dev/null > /dev/null; then
err 'Docker is not running. Run `docker info` for more information.'
exit 1
fi

if [[ $? -ne 0 ]]; then
# This is another error that may require reset of the sandbox
err "Detected an error from the docker command."
if [[ $# -eq 0 ]]; then
NETWORK=$(cat data/network)
Expand All @@ -184,7 +193,6 @@ sandbox () {
statusline "Starting '$NETWORK' sandbox..."
up $NETWORK
fi
set -e
else
statusline "\nBuilding a new Docker Image..."
docker build \
Expand Down