Skip to Content.
Sympa Menu

sm-commit - [SM-Commit] GIT changes to master cauldron by Justin Boffemmyer (b3cb81a571222f2de81787f12ce755e22ed167b7)

sm-commit AT lists.ibiblio.org

Subject: Source Mage code commit list

List archive

Chronological Thread  
  • From: Justin Boffemmyer <scm AT sourcemage.org>
  • To: sm-commit AT lists.ibiblio.org
  • Subject: [SM-Commit] GIT changes to master cauldron by Justin Boffemmyer (b3cb81a571222f2de81787f12ce755e22ed167b7)
  • Date: Thu, 23 Jun 2011 19:28:36 -0500

GIT changes to master cauldron by Justin Boffemmyer <flux AT sourcemage.org>:

lib/libcolor | 6 --
lib/liberror | 127
++++++++++++++++++++++++++++++++++++++++++--------------
ward/libruntime | 6 ++
ward/libward | 2
4 files changed, 104 insertions(+), 37 deletions(-)

New commits:
commit b3cb81a571222f2de81787f12ce755e22ed167b7
Author: Justin Boffemmyer <flux AT sourcemage.org>
Commit: Justin Boffemmyer <flux AT sourcemage.org>

lib/liberror: error checking functions

Added a new function, liberror_check, to test for the presence of a
non-fatal error on the error stack ($?). If it finds such an error, a
corresponding error message is printed via liberror_print_error. Also
rewrote liberror_check_fatal_error to leverage the newer liberror_die
(and in turn liberror_print_error) better, and renamed it to
liberror_check_fatal (less typing is better). Both functions can
optionally pass extended error message information along, as well as
optionally override the error code used from the one on the stack to one
supplied directly as the first parameter to the function.

commit 3025e1a07277725a4569cffbedf528d10e4311b4
Author: Justin Boffemmyer <flux AT sourcemage.org>
Commit: Justin Boffemmyer <flux AT sourcemage.org>

lib/liberror: allow for additional error info

Enable liberror_print_error to output additional error message
information after the regular error message. This can be used, for
example, to report via the regular error message that there was a
problem creating a file, and then through the additional information
which file failed to be created. liberror_die was also updated to allow
for passing this information to liberror_print_error.

commit 30fb5b1bd270580d49062b7cd9ffed7fc11d8cd5
Author: Justin Boffemmyer <flux AT sourcemage.org>
Commit: Justin Boffemmyer <flux AT sourcemage.org>

lib/liberror: make use of override output vars

Rather than accept an output location as an argument, simply use the
global output variables for stderr and stdout. Changing the output
location should happen by overriding the values of those variables
instead.

commit 516952ae6bebc74bb5867bda851ecb82d19d3c66
Author: Justin Boffemmyer <flux AT sourcemage.org>
Commit: Justin Boffemmyer <flux AT sourcemage.org>

lib/liberror: don't force stdout/stderr

Only define LIBERR_STDOUT and LIBERR_STDERR if they aren't already
defined. This allows for more flexibility in redirecting error message
output, say to a log file. Normally this could be overridden later, but
being able to redirect earlier on is more essential, since there may be
errors that occur before an override is to be performed in the loading
chain.

commit 7fc35fec66ab4a6518fc9e5886c1b5c5195a51bc
Author: Justin Boffemmyer <flux AT sourcemage.org>
Commit: Justin Boffemmyer <flux AT sourcemage.org>

lib/liberror: fold count into liberror_add_error

Currently, the implementation does not allow/account for either removing
error codes/messages, or adding them spuriously. They are always only
appended to the end of the list. There is therefore no need for
maintaining a separate count variable of the number of defined
codes/messages, as the same value can be ascertained simply by taking
the current size of the message array. This assumes that there are
always messages matching codes and vice versa, but this is guaranteed by
the use of liberror_add_error (if you manually adjust the codes or
messages, then it is your responsibility to account for any problems).
Folding the count tracking into liberror_add_error makes the
implementation a little cleaner and more localized.

commit 42b5e0ec279b6bd79c140a7b0c8b5d2a1e6ff436
Author: Justin Boffemmyer <flux AT sourcemage.org>
Commit: Justin Boffemmyer <flux AT sourcemage.org>

lib/libcolor: make LIBCOLOR_NOCOLOR really no color

Previously, defining LIBCOLOR_NOCOLOR=yes resulted in monochrome output
colors, using the bold attribute. The colors are now completely disabled
with LIBCOLOR_NOCOLOR=yes. For monochrome output, a separate colorscheme
should be defined and loaded after libcolor itself is loaded.

commit 607244711be5b98b4d21486ef16cc06c3da5ae67
Author: Justin Boffemmyer <flux AT sourcemage.org>
Commit: Justin Boffemmyer <flux AT sourcemage.org>

ward: section comments in libruntime

Use comments to separate the purely basic assertions from more
complicated runtime tests in libruntime.

commit d7b90babaf207b2b1c52a194ea1fd78a0a7c415a
Author: Justin Boffemmyer <flux AT sourcemage.org>
Commit: Justin Boffemmyer <flux AT sourcemage.org>

ward: fix variable name

Accidentally had CAULDRON_NULL as a leftover from a copy/paste.
Corrected to the correct variable name (WARD_NULL).

diff --git a/lib/libcolor b/lib/libcolor
index 7290289..d13b553 100644
--- a/lib/libcolor
+++ b/lib/libcolor
@@ -49,9 +49,7 @@ LIBCOLOR_SYMLINK_COLOR="${LIBCOLOR_BOLD}${LIBCOLOR_CYAN}"
function libcolor_notice() {
if [[ "$LIBCOLOR_NOCOLOR" = "yes" ]]
then
- echo -ne "$LIBCOLOR_BOLD"
echo -n "$@"
- echo -ne "$LIBCOLOR_NORMAL"
else
echo -ne "$LIBCOLOR_NOTICE_COLOR"
echo -n "$@"
@@ -68,9 +66,7 @@ function libcolor_notice() {
function libcolor_warn() {
if [[ "$LIBCOLOR_NOCOLOR" = "yes" ]]
then
- echo -ne "$LIBCOLOR_BOLD"
echo -n "$@"
- echo -ne "$LIBCOLOR_NORMAL"
else
echo -ne "$LIBCOLOR_WARN_COLOR"
echo -n "$@"
@@ -87,9 +83,7 @@ function libcolor_warn() {
function libcolor_error() {
if [[ "$LIBCOLOR_NOCOLOR" = "yes" ]]
then
- echo -ne "$LIBCOLOR_BOLD"
echo -n "$@"
- echo -ne "$LIBCOLOR_NORMAL"
else
echo -ne "$LIBCOLOR_ERROR_COLOR"
echo -n "$@"
diff --git a/lib/liberror b/lib/liberror
index 3fba5ee..561dc0b 100755
--- a/lib/liberror
+++ b/lib/liberror
@@ -19,8 +19,8 @@

#-------------------------------------------------------------------------------
# Output Stream Definitions

#-------------------------------------------------------------------------------
-LIBERR_STDOUT=1
-LIBERR_STDERR=2
+LIBERR_STDOUT=${LIBERR_STDOUT:-1}
+LIBERR_STDERR=${LIBERR_STDERR:-2}


#-------------------------------------------------------------------------------
# ERROR definitions
@@ -36,12 +36,6 @@ ERR_MSGS=(
)


#-------------------------------------------------------------------------------
-# Internal definitions - do not use in external/public code!
-#-------------------------------------------------------------------------------
-# error counter -- for internal use only!
-LIBERR_ERRCODE_COUNT=2
-
-#-------------------------------------------------------------------------------
# Function definitions

#-------------------------------------------------------------------------------

#-------------------------------------------------------------------------------
@@ -57,40 +51,39 @@ LIBERR_ERRCODE_COUNT=2
function liberror_add_error() {
local code="$1"
local msg="$2"
+ local count="${#ERR_MSGS[@]}"

[[ -z "$code" || -z "$msg" ]] && return $ERR_FATAL

- [[ "$LIBERR_ERRCODE_COUNT" -ge 255 ]] && return $ERR_FATAL
+ [[ "$count" -ge 255 ]] && return $ERR_FATAL

# define the error code itself
- eval "$code"=$LIBERR_ERRCODE_COUNT
+ eval "$code"=$count

# define a corresponding message in the message array
- ERR_MSGS[$LIBERR_ERRCODE_COUNT]="$msg"
- ((LIBERR_ERRCODE_COUNT++))
+ ERR_MSGS[$count]="$msg"

return $ERR_OK
}


#-------------------------------------------------------------------------------
## @param error number
-## @param output stream (default is 1 [stdout], 2 for stderr)
+## @param error information (optional)
##
## Prints the corresponding error message for the given error type (number,
-## defined as a variable in an errorcodes file, e.g. $ERR_FATAL) to the given
-## output stream (defaults to STDOUT) in the configured error message color.
+## defined as a variable in an errorcodes file, e.g. $ERR_FATAL) to
+## LIBERR_STDOUT. If the optional error information is provided as the second
+## parameter, then it will be appended to the error message before being
output.
##
## If libcolor is sourced and color is not specifically disabled, then the
error
-## message will be output in color.
+## message will be output in the configured error message color.
##

#-------------------------------------------------------------------------------
function liberror_print_error() {
- local error=$1
+ local error="$1"
+ local info="$2"
local errmsg="${ERR_MSGS[${error}]}"
- local output=$2
-
- # if no 2nd argument, use STDOUT as default
- output=${output:=$LIBERR_STDOUT}
+ local output="$LIBERR_STDOUT"

# exit if $errmsg not defined
[[ -z "$errmsg" ]] && return 1
@@ -107,6 +100,9 @@ function liberror_print_error() {
eval echo "$errmsg" >&$output
fi
else
+ # tack on the error info to the errmsg if defined
+ [[ -n "$info" ]] && errmsg="$errmsg: $info"
+
# output using libcolor if available
if [[ "$(type -t libcolor_error)" == "function" ]]
then
@@ -122,35 +118,106 @@ function liberror_print_error() {


#-------------------------------------------------------------------------------
## @param error number
+## @param error information (optional)
##
## Calls liberror_print_error with the error number passed as the first
-## argument, then exits with the same error number. If no error number was
-## passed in then the function returns with error rather than exiting.
+## argument, and optionally error information as the second argument, then
exits
+## with the same error number. If no error number was passed in then the
+## function returns with error rather than exiting.
##

#-------------------------------------------------------------------------------
function liberror_die() {
- local error=$1
+ local error="$1"
+ local info="$2"
+ local LIBERR_STDOUT="$LIBERR_STDERR"

# exit if $errmsg not defined
[[ -z "$error" ]] && return 1

# print the corresponding error message on STDERR
- liberror_print_error $error $LIBERR_STDERR
+ liberror_print_error "$error" "$info"

# die is used for fatal errors, so exit to the parent process rather than
# returning to the caller
- exit $error
+ exit "$error"
}


#-------------------------------------------------------------------------------
+## @param error name (optional)
+## @param error information (optional)
+##
+## Calls liberror_print_error if current exit status (from a previous
command)
+## holds an error that is defined. If error name is provided as the first
+## argument, then it will override the value of $? and use the provided error
+## name instead. If error information is provided as an argument, then it
will
+## be added to the defined error message as additional information.
+##
+## Note that, while both parameters are optional, the error name must be the
+## first argument, but error information is allowed to be the only argument.
+## Thus, if you wish to override the error name but not provide additional
error
+## information, the error name should be given as the first argument and an
+## empty string given as the error information. An example follows.
+##
+## liberror_check ERR_NAME ""
+##
+#-------------------------------------------------------------------------------
+function liberror_check() {
+ local error="$?"
+ local info=""
+
+ # if we were given two parameters, the first is the error name (override),
and
+ # the second is the info message. Otherwise, the first parameter (if
given) is
+ # the info message, and error is taken from the $? resulting from whatever
+ # command/function was run before calling the present function.
+ if [[ "$#" -eq 2 ]]
+ then
+ error="$1"
+ info="$2"
+ else
+ info="$1"
+ fi
+
+ [[ "$error" -gt 0 ]] && liberror_print_error "$error" "$info"
+
+ return $ERR_OK
+}
+
+#-------------------------------------------------------------------------------
+## @param error name (optional)
+## @param error information (optional)
##
## Calls liberror_die if current exit status (from a previous command) holds
an
-## error. If there's an error, the error is passed to liberror_die.
Otherwise,
-## it returns $ERR_OK.
+## error that is defined. If error name is provided as the first argument,
then
+## it will override the value of $? and use the provided error name instead.
If
+## error information is provided as an argument, then it will be added to the
+## defined error message as additional information.
+##
+## Note that, while both parameters are optional, the error name must be the
+## first argument, but error information is allowed to be the only argument.
+## Thus, if you wish to override the error name but not provide additional
error
+## information, the error name should be given as the first argument and an
+## empty string given as the error information. An example follows.
+##
+## liberror_check_fatal ERR_NAME ""
##

#-------------------------------------------------------------------------------
-function liberror_check_fatal_error() {
- [[ $? ]] && liberror_die $?
+function liberror_check_fatal() {
+ local error="$?"
+ local info=""
+
+ # if we were given two parameters, the first is the error name (override),
and
+ # the second is the info message. Otherwise, the first parameter (if
given) is
+ # the info message, and error is taken from the $? resulting from whatever
+ # command/function was run before calling the present function.
+ if [[ "$#" -eq 2 ]]
+ then
+ error="$1"
+ info="$2"
+ else
+ info="$1"
+ fi
+
+ [[ "$error" -gt 0 ]] && liberror_die "$error" "$info"

return $ERR_OK
}
diff --git a/ward/libruntime b/ward/libruntime
index 3363159..d6a49f5 100644
--- a/ward/libruntime
+++ b/ward/libruntime
@@ -15,6 +15,9 @@
##

#-------------------------------------------------------------------------------

+#-------------------------------------------------------------------------------
+# BEGIN: Basic assertions (simple test/fail cases)
+#-------------------------------------------------------------------------------
function ward_file() {
local dir="$1"

@@ -48,6 +51,9 @@ function ward_symlink_dir() {

ward_dir "$link" || return 1
}
+#-------------------------------------------------------------------------------
+# END: Basic assertions (simple test/fail cases)
+#-------------------------------------------------------------------------------


#-------------------------------------------------------------------------------
## @param base path to sys target (optional)
diff --git a/ward/libward b/ward/libward
index a8fd6dd..4612b88 100644
--- a/ward/libward
+++ b/ward/libward
@@ -63,7 +63,7 @@ unset ward_fatal_error
function ward_load_library() {
local lib="$1"

- . "$WARD_PATH/$lib" 2>$CAULDRON_NULL
+ . "$WARD_PATH/$lib" 2>$WARD_NULL
liberror_check_fatal_error
}




  • [SM-Commit] GIT changes to master cauldron by Justin Boffemmyer (b3cb81a571222f2de81787f12ce755e22ed167b7), Justin Boffemmyer, 06/23/2011

Archive powered by MHonArc 2.6.24.

Top of Page