6ebab10 safer, simpler error handling in lbmk

Authored and Committed by Leah Rowe 4 months ago
    safer, simpler error handling in lbmk
    
    in shell scripts, a function named the same as a program included in
    the $PATH will override that program. for example, you could make a
    function called ls() and this would override the standand "ls".
    
    in lbmk, a part of it was first trying to run the "fail" command,
    deferring to "err", because some scripts call fail() which does
    some minor cleanup before calling err.
    
    in most cases, fail() is not defined, and it's possible that the user
    could have a program called "fail" in their $PATH, the behaviour of
    which we could not determine, and it could have disastrous effects.
    
    lbmk error handling has been re-engineered in such a way that the
    err function is defined in a variable, which defaults to err_ which
    calls err_, so defined under include/err.sh.
    
    in functions that require cleanup prior to error handling, a fail()
    function is still defined, and err is overridden, thus:
    
    err="fail"
    
    this change has made xx_() obsolete, so now only x_ is used. the x_
    function is a wrapper that can be used to run a command and exit with
    non-zero status (from lbmk) if the command fails. the xx_ command
    did the same thing, but called fail() which would have called err();
    now everything is $err
    
    example:
    
    	rm -f "$filename" || err "could not delete file"
    
    this would now be:
    
    	rm -f "$filename" || $err "could not delete file"
    
    overriding of err= must be done *after* including err.sh. for
    example:
    
    err="fail"
    . "include/err.sh"
    
    ^ this is wrong. instead, one must do:
    
    . "include/err.sh"
    err="fail"
    
    this is because err is set as a global variable under err.sh
    
    the new error handling is much cleaner, and safer. it also reduces
    the chance of mistakes such as: calling err when you meant to
    call fail. this is because the standard way is now to call $err,
    so you set err="fail" at the top of the script and all is well.
    
    Signed-off-by: Leah Rowe <leah@libreboot.org>
    
        
file modified
+17 -16
file modified
+7 -18
file modified
+21 -21
file modified
+11 -11
file modified
+4 -5
file modified
+18 -18
file modified
+3 -3
file modified
+46 -46
file modified
+15 -15
file modified
+27 -27
file modified
+22 -22