Skip to content

Commit

Permalink
Better error handling (#12)
Browse files Browse the repository at this point in the history
* Do not ignore errors if data folder corrupted

Previously, `set +e` was used, which was then carried to `ask_clean`
This may explain the problem seen in issue #9.

* Test if docker running before asking to reset sandbox

Avoid users resetting sandbox before realizing that
the issue was that Docker was not running.
  • Loading branch information
fabrice102 authored Mar 17, 2020
1 parent 819fb5e commit 80efe42
Showing 1 changed file with 12 additions and 4 deletions.
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

0 comments on commit 80efe42

Please sign in to comment.