Browse Source

Corrects ERR trap

function fw_exists was returning a non-zero code, which was always
triggering the ERR trap. This commit fixes that issue for the "go"
dependency - it still needs to be fixed for others.

This also updates the ERR trap to have access to the entire
bash function stack, which would be very useful for debugging
Hamilton Turner 11 years ago
parent
commit
220f2c4061
2 changed files with 20 additions and 12 deletions
  1. 18 10
      toolset/setup/linux/bash_functions.sh
  2. 2 2
      toolset/setup/linux/languages/go.sh

+ 18 - 10
toolset/setup/linux/bash_functions.sh

@@ -25,14 +25,20 @@ FW_dep_error=0
 # Have we seen any errors?
 # Have we seen any errors?
 FW_any_errors=0
 FW_any_errors=0
 fw_traperror () {
 fw_traperror () {
-  depend=$1
-  err=$2 # error status
-  line=$3 # LINENO
-  command="$4"
+  depend=$1      # Dependency being installed
+  err=$2         # error status
+  line=$3        # Current line
+  command="$4"   # Bash command
+  IFS=':' read -a funcstack <<< "$5" # Stack (function names)
+  IFS=':' read -a bashstack <<< "$6" # Stack (file names)
+  IFS=':' read -a linestack <<< "$7" # Stack (line numbers)
   FW_dep_error=1
   FW_dep_error=1
   FW_any_errors=1
   FW_any_errors=1
-
-  echo "ERROR: ${depend}.sh at line $line - command '$command' exited with status: $err"
+  
+  echo "ERROR: $(echo ${bashstack[1]#$FWROOT}): Command '$command' exited with status $err (dependency=$depend)"
+  #echo "  Function stack    : ${funcstack[@]}"
+  #echo "  Bash source stack : ${bashstack[@]}"
+  #echo "  Bash line stack   : ${linestack[@]}"
 }
 }
 
 
 # Requires dependencies to come in order e.g. Nimrod before
 # Requires dependencies to come in order e.g. Nimrod before
@@ -48,7 +54,7 @@ fw_depends() {
   do
   do
     depend=$(echo $depend | awk '{print tolower($0)}')
     depend=$(echo $depend | awk '{print tolower($0)}')
     echo Searching for $depend
     echo Searching for $depend
-    trap 'fw_traperror $depend $? $LINENO "$BASH_COMMAND"'  ERR
+    trap 'fw_traperror $depend $? $LINENO "$BASH_COMMAND" $(printf ":%s" ${FUNCNAME[@]}) $(printf ":%s" ${BASH_SOURCE[@]}) $(printf ":%s" ${BASH_LINENO[@]})'  ERR
     retcode=0
     retcode=0
     if [ -f ../toolset/setup/linux/systools/${depend}.sh ]; then
     if [ -f ../toolset/setup/linux/systools/${depend}.sh ]; then
       echo Installing system tool: $depend 
       echo Installing system tool: $depend 
@@ -87,12 +93,14 @@ fw_depends() {
   return $FW_any_errors
   return $FW_any_errors
 }
 }
 
 
-# Exits 0 if file or directory exists
+# Echo's 0 if file or directory exists
+# To be used with or || blocks, avoids triggering our ERR 
+# trap with a return 1 statement
 fw_exists() {
 fw_exists() {
   if [ -f $1 ] || [ -d $1 ]; then
   if [ -f $1 ] || [ -d $1 ]; then
-    return 0
+    echo 0
   else
   else
-    return 1
+    echo 1
   fi 
   fi 
 }
 }
 
 

+ 2 - 2
toolset/setup/linux/languages/go.sh

@@ -1,7 +1,7 @@
 #!/bin/bash
 #!/bin/bash
 
 
-fw_exists go
-[ $? -ne 0 ] || { return 0; }
+RETCODE=$(fw_exists go)
+[ ! "$RETCODE" == 0 ] || { return 0; }
 
 
 fw_get https://storage.googleapis.com/golang/go1.3.linux-amd64.tar.gz
 fw_get https://storage.googleapis.com/golang/go1.3.linux-amd64.tar.gz
 fw_untar go1.3.linux-amd64.tar.gz
 fw_untar go1.3.linux-amd64.tar.gz