summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDieter Plaetinck <dieter@plaetinck.be>2011-04-03 22:18:14 +0200
committerDieter Plaetinck <dieter@plaetinck.be>2011-04-03 22:19:32 +0200
commit11a21c24bf08245157c6d0bb2ca59499cd095656 (patch)
tree32319a2c848cf482fd43f8368cae9c5f2ac3b093
parent746e1ade11eece4ec6ef1553fb5e7f38fb580023 (diff)
debug calls to die_error, they are very important
-rw-r--r--libui.sh22
1 files changed, 16 insertions, 6 deletions
diff --git a/libui.sh b/libui.sh
index b3a4bc0..988c40e 100644
--- a/libui.sh
+++ b/libui.sh
@@ -88,13 +88,22 @@ seteditor() {
# display error message and die
-# Do not call other functions like debug, notify, .. here because that might cause loops!
die_error ()
{
+ DIE_ERROR=1 # avoids functions the debug function relies on (i.e. check_is_in) calling us back, causing a loop
+ debug 'UI' "die_error $@"
echo -e "ERROR: $@" >&2
exit 2
}
+# like die_error, but only to be called by debug function, invocations of this function
+# don't get debugged to avoid loops
+die_error_raw ()
+{
+ echo -e "ERROR: $@" >&2
+ exit 2
+}
+
# display warning message
# $1 title
@@ -154,21 +163,22 @@ log ()
# $1 = one or more debug categories (must be in a list of specified categories. see init function) (separated by spaces)
# Useful when grepping in the logfile
# $2 = string to log
+# always make sure this function never calls die_error, not even indirectly through other functions we call here, to avoid loops
debug ()
{
[ "$LIBUI_DEBUG" = "1" ] || return;
- [ -n "$1" ] || die error "you must specify at least one (non-empty) debug category"
- [ -n "$2" ] || die_error "debug \$2 cannot be empty"
+ [ -n "$1" ] || die error_raw "you must specify at least one (non-empty) debug category"
+ [ -n "$2" ] || die_error_raw "debug \$2 cannot be empty"
for cat in $1
do
- check_is_in $cat "${LIBUI_DEBUG_CATEGORIES[@]}" || die_error "debug \$1 contains a value ($cat) which is not a valid debug category"
+ [ -n "$DIE_ERROR" ] || check_is_in $cat "${LIBUI_DEBUG_CATEGORIES[@]}" || die_error_raw "debug \$1 contains a value ($cat) which is not a valid debug category"
done
for file in $LIBUI_LOG_FILE; do
[ -z "$file" ] && continue;
dir=$(dirname $file)
- mkdir -p $dir || die_error "Cannot create log directory $dir"
+ mkdir -p $dir || die_error_raw "Cannot create log directory $dir"
str="[DEBUG $1 ] $2"
- echo -e "$str" >> $file || die_error "Cannot debug $str to $file"
+ echo -e "$str" >> $file || die_error_raw "Cannot debug $str to $file"
done
}