Project

General

Profile

« Previous | Next » 

Revision 8981

lib/util.sh: exceptions: added log_e (), which prints a "command exited with error" message (like make) when applicable

View differences:

util.sh
40 40
function save_e () { "$@"; e=$?; rethrow; } # rethrow because e= clears $?
41 41
alias save_e='declare e; save_e ' # last space alias-expands next word
42 42

  
43
function log_e () # usage: log_e cmd... [ || use $e (or $?) ]
44
{
45
	if ! save_e "$@"; then
46
		echo "! $*" >&2
47
		echo "! command exited with error $e" >&2
48
		rethrow
49
	fi
50
}
51
alias log_e='log_e ' # last space alias-expands next word
52

  
43 53
# usage: try cmd...; ignore status; if catch status; then ...; fi; end_try
44 54

  
45 55
function try () { "save_e" "$@" || true; }

Also available in: Unified diff