Revision 9027
Added by Aaron Marcuse-Kubitza over 11 years ago
lib/sh/util.sh | ||
---|---|---|
45 | 45 |
|
46 | 46 |
#### exceptions |
47 | 47 |
|
48 |
# usage: cmd || { save_e; ...; rethrow; } |
|
49 |
alias save_e='e=$?' |
|
48 | 50 |
alias rethrow='return "$e"' |
49 | 51 |
alias rethrow_subshell='exit "$e"' |
50 | 52 |
|
... | ... | |
52 | 54 |
if self_being_included; then |
53 | 55 |
|
54 | 56 |
# usage: save_e_cmd cmd... || { use $e (or $?); rethrow; } |
55 |
function save_e_cmd () { "$@"; e=$?; rethrow; } # rethrow because e= clears $?
|
|
57 |
function save_e_cmd () { "$@"; save_e; rethrow; } # rethrow because e= clears $?
|
|
56 | 58 |
alias save_e_cmd='declare e; save_e_cmd ' # last space alias-expands next word |
57 | 59 |
|
58 | 60 |
function log_e () # usage: log_e cmd... [ || use $e (or $?) ] |
59 | 61 |
{ |
60 | 62 |
if "$@"; then :; else # don't use ! because that resets $? |
61 |
e=$?
|
|
63 |
save_e
|
|
62 | 64 |
echo "! $*" >&2 |
63 | 65 |
echo "! command exited with error $e" >&2 |
64 | 66 |
rethrow |
Also available in: Unified diff
lib/sh/util.sh: exceptions: added save_e, now an alias for e=$?. added save_e/rethrow usage.