Project

General

Profile

« Previous | Next » 

Revision 9035

lib/sh/util.sh: log_e (): restructured as an error handler to put after save_e rather than as a wrapper around the entire command. this allows it to be used with any kind of expression (such as boolean expressions with !), not just single commands.

View differences:

lib/sh/util.sh
54 54
fi # load new aliases
55 55
if self_being_included; then
56 56

  
57
function log_e () # usage: log_e cmd... [ || use $e (or $?) ]
58
{
59
	if "$@"; then :; else # don't use ! because that resets $?
60
		save_e
61
		echo "! $*" >&2
62
		echo "! command exited with error $e" >&2
63
		rethrow
64
	fi
65
}
66
alias log_e='log_e ' # last space alias-expands next word
57
# usage: cmd || { save_e; log_e; ...; rethrow; }
58
log_e () { echo "! command exited with error $e" >&2; }
67 59

  
68 60
# usage: try cmd...; ignore status; if catch status; then ...; fi; end_try
69 61

  
......
257 249

  
258 250
# auto-removes a command's output file on error (like make's .DELETE_ON_ERROR)
259 251
function to_file () # usage: stdout=... to_file cmd...
260
{ : "${stdout?}"; log_e "$@" >"$stdout" || { save_e; rm "$stdout"; rethrow; }; }
252
{ : "${stdout?}"; "$@" >"$stdout" || { save_e; log_e; rm "$stdout"; rethrow;}; }
261 253
alias to_file='to_file ' # last space alias-expands next word
262 254

  
263 255
run_args_cmd () # runs the command line args command

Also available in: Unified diff