Skip to Content.
Sympa Menu

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

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 (3270a04793baa3c179b6a5c5e1131fe3cbe4057d)
  • Date: Thu, 4 Jun 2009 23:39:13 -0500

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

liberror | 161
+++++++++++++++++++++++++++++++++++++++++++++++----------------
1 files changed, 122 insertions(+), 39 deletions(-)

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

liberror: add error checking to geterror()

Added some error checking to geterror() so that it would return 1 if it
couldn't process the error code.

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

liberror: clarify checkerror() description header

Clarify the description header for checkerror() so that it both more
accurately describes the function and gives more detail as to how to use
the function.

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

liberror: correct and improve checkerror()

Corrected the previous faults in the implementation of checkerror(), as
well as improving it by adding additional functionality. It now makes
use of the liberror context variable and calls geterror() to get an
error name if one wasn't supplied. This enables checkerror() to be used
in a more generic way, in addition to only checking for a specific
error.

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

liberror: rename prefix to checkerror()

Renamed the prefix of checkerror() from cauldron_ to liberror_.

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

liberror: use preserved return value

Preserve the return value to check before doing anything else in the
function. All tests, commands, etc. run will modify the value of $?, so
it needs to be preserved or what is tested later will actually be the
return value of function-internal processing, rather than the value the
caller wants to check.

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

liberror: implement printerror()

Previously printerror() was implemented with "place-holder" code. The
code has now been fleshed out, where the error message is actually
filled in instead of printing a null variable. Also, it isn't hardcoded
for only cauldron errors, but can now also handle enchant errors.

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

liberror: new function, get error name from int

Returns the error name (type) that corresponds to the given (as arg1)
error number (i.e., return value).

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

liberror: add context variable

liberror is used by both cauldron as well as enchant, so knowing which
context liberror is being accessed from is useful (separation of
error codes, error messages, etc.). This variable can be set in the
caller, but defaults to cauldron (enchant *must* set this).

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

liberror: implement error messages

Implement the actual messages that correspond to different error codes,
to be printed/passed by the error checking/reporting functions.

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

liberror: implement more error codes and reorder

Implemented the other error codes currently in use in libcauldron as
well as a new error code for fatal errors. Also reordered the error
codes in a more logical way (fatal should be "first").

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

liberror: remove "local" keyword

Remove incorrect usage of "local" since these variables aren't within a
function.

diff --git a/liberror b/liberror
index 2e584b6..09f0069 100755
--- a/liberror
+++ b/liberror
@@ -19,72 +19,155 @@

#-------------------------------------------------------------------------------
# Local global variables

#-------------------------------------------------------------------------------
-local CDEFAULT_COLOR="\e[0m"
-local CBOLD="\e[1m"
-local CBLACK="\e[30m"
-local CRED="\e[31m"
-local CGREEN="\e[32m"
-local CYELLOW="\e[33m"
-local CBLUE="\e[34m"
-local CVIOLET="\e[35m"
-local CCYAN="\e[36m"
-local CWHITE="\e[37m"
-
-local CERR_COLOR="${RED}${BOLD}"
-local EERR_COLOR="${RED}${BOLD}"
-
-local CSPELL_COLOR="${WHITE}${BOLD}\e[40m"
-local CVERSION_COLOR="${WHITE}${BOLD}\e[40m"
-local CQUERY_COLOR="${YELLOW}${BOLD}"
-local CDISPEL_COLOR="${YELLOW}${BOLD}"
-local CCHECK_COLOR="${CYAN}"
-local CRESURRECT_COLOR="${GREEN}${BOLD}"
-local CFILE_COLOR="${GREEN}${BOLD}"
-local CSYMLINK_COLOR="${CYAN}${BOLD}"
-local CPROBLEM_COLOR="${RED}${BOLD}"
-local CMESSAGE_COLOR="${CYAN}"
+CDEFAULT_COLOR="\e[0m"
+CBOLD="\e[1m"
+CBLACK="\e[30m"
+CRED="\e[31m"
+CGREEN="\e[32m"
+CYELLOW="\e[33m"
+CBLUE="\e[34m"
+CVIOLET="\e[35m"
+CCYAN="\e[36m"
+CWHITE="\e[37m"
+
+CERR_COLOR="${RED}${BOLD}"
+EERR_COLOR="${RED}${BOLD}"
+
+CSPELL_COLOR="${WHITE}${BOLD}\e[40m"
+CVERSION_COLOR="${WHITE}${BOLD}\e[40m"
+CQUERY_COLOR="${YELLOW}${BOLD}"
+CDISPEL_COLOR="${YELLOW}${BOLD}"
+CCHECK_COLOR="${CYAN}"
+CRESURRECT_COLOR="${GREEN}${BOLD}"
+CFILE_COLOR="${GREEN}${BOLD}"
+CSYMLINK_COLOR="${CYAN}${BOLD}"
+CPROBLEM_COLOR="${RED}${BOLD}"
+CMESSAGE_COLOR="${CYAN}"


#-------------------------------------------------------------------------------
# ERROR definitions

#-------------------------------------------------------------------------------
# cauldron errors
-CERR_OK=0
-CERR_ARCHIVE=1
-CERR_CHROOT=2
-CERR_CLEANFILE=3
+CERR_OK=0 # everything is good
+CERR_FATAL=1 # fatal error (missing cauldron libs, etc.)
+CERR_ARCHIVE=2 # problem creating archives
+CERR_CHROOT=3 # problem with a chroot
+CERR_CLEANFILE=4 # missing cleaner files
+CERR_TARGETSORCERY=5 # missing target sorcery files
+CERR_HOSTSORCERY=6 # sorcery not installed on host
+
+# cauldron error messages
+CERR_MSG=(
+ "operation succeeded" # CERR_OK
+ "fatal error" # CERR_FATAL
+ "sorcery not set to archive" # CERR_ARCHIVE
+ "not in chroot" # CERR_CHROOT
+ "cleanfile not found" # CERR_CLEANFILE
+ "could not load target sorcery" # CERR_TARGETSORCERY
+ "could not load host sorcery" # CERR_HOSTSORCERY
+ )

# enchant errors
EERR_OK=0
EERR_STEP=1

+# enchant error messages
+EERR_MSG=(
+ "operation succeeded" # EERR_OK
+ "step error" # EERR_STEP
+ )
+
+# liberror context - should be either C for cauldron or E for enchant,
defaults
+# to cauldron context ("C").
+LIBERROR_CONTEXT=${LIBERROR_CONTEXT:-C}
+

#-------------------------------------------------------------------------------
# Function definitions

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

#-------------------------------------------------------------------------------
-## @param type
+## @param error name (string)
##
## Checks for an error condition (via $?), and if found it will return an
error
-## of the specified type (arg1).
+## of the specified type (arg1) if given, or of the matching type if no arg
was
+## given.
##

#-------------------------------------------------------------------------------
-function cauldron_checkerror() {
- local type=$1
- local error=
+function liberror_checkerror() {
+ # store the return value to preserve it
+ local rc="$?"
+ local error="$1"

- if [[ $? -gt 0 ]]
+ if [[ $rc -gt 0 ]]
then
- error=$type
+ if [[ -z $error || $rc -ne ${!error} ]]
+ then
+ error="$(liberror_geterror $rc)"
+ fi
else
- error="${${type:0:1}ERR_OK}"
+ error="${LIBERROR_CONTEXT}ERR_OK"
fi
- return $error
+ [[ -z $error ]] && return 1
+ echo $error
+ return 0
+}
+
+#-------------------------------------------------------------------------------
+## @param error (int)
+##
+## Finds a matching error type for the given error number. This is used to
get
+## an error name from a raw return code, for example.
+##
+#-------------------------------------------------------------------------------
+function liberror_geterror() {
+ local error=$(set | grep "${LIBERROR_CONTEXT}ERR_[A-Z]*=$1" | cut -d = -f
1)
+
+ [[ -z $error ]] && return 1
+ echo "$error"
+ return 0
}

-function cauldron_printerror() {
+#-------------------------------------------------------------------------------
+## @param error name (string)
+##
+## Prints the corresponding error message for the given error type (string,
+## defined in this file, e.g. CERR_ARCHIVE) to STDOUT in the configured error
+## message color.
+##
+#-------------------------------------------------------------------------------
+function liberror_printerror() {
local error=$1
local errmsg=

- echo "$CERR_COLOR" "$errmsg" "$CDEFAULT_COLOR"
+ # check if we are in cauldron or enchant
+ if [[ $LIBERROR_CONTEXT == C ]]
+ then
+ errmsg="${CERR_MSG[${!error}]}"
+ # exit if $errmsg not defined
+ [[ -z $errmsg ]] && return 1
+
+ if [[ ${!error} -eq 0 ]]
+ then
+ # print a cauldron OK message
+ echo "$CMESSAGE_COLOR" "$errmsg" "$CDEFAULT_COLOR"
+ else
+ # print a cauldron error message
+ echo "$CERR_COLOR" "error: ${errmsg}!" "$CDEFAULT_COLOR"
+ fi
+ else
+ errmsg="${EERR_MSG[${!error}]}"
+ # exit if $errmsg not defined
+ [[ -z $errmsg ]] && return 1
+
+ if [[ ${!error} -eq 0 ]]
+ then
+ # print an enchant OK message
+ echo "$EMESSAGE_COLOR" "$errmsg" "$EDEFAULT_COLOR"
+ else
+ # print an enchant error message
+ echo "$EERR_COLOR" "error: ${errmsg}!" "$EDEFAULT_COLOR"
+ fi
+ fi || return 1
+ return 0
}


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



  • [SM-Commit] GIT changes to master cauldron by Justin Boffemmyer (3270a04793baa3c179b6a5c5e1131fe3cbe4057d), Justin Boffemmyer, 06/05/2009

Archive powered by MHonArc 2.6.24.

Top of Page