~mhysterio/sintel-media/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
# This file is part of Sintel.
#
# Sintel is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Sintel is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Sintel.  If not, see <https://www.gnu.org/licenses/>.
#
#
# Control de errores
#set -o pipefail  # trace ERR through pipes
#set -o errtrace  # trace ERR through 'time command' and other functions
set -eE

function error.info() {
    echo "error - Manejo de errores de Sintel"
    echo
    echo "En caso de producirse un error se invocará automáticamente"
    echo "la función 'error' que informará al usuario de en qué"
    echo "parte del script se produjo, incluyendo la pila de llamadas."
    echo
    echo
}

function error.stackTrace() {
    echo "Stack trace:"
    let i=1
    for func in "${FUNCNAME[@]}"; do
	#[[ $i > 2 ]] && echo "   $func"
	echo "    $func"
	(( i++ ))
    done
}

function error.stackTrace.info() {
    echo
    echo "error.stackTrace - Muestra la pila de llamadas"
    echo
    echo "Lista las funciones que han sido llamadas en orden"
    echo "inverso. Permite hacerse una idea de dónde se ha"
    echo "producido un error. Esta función es llamada desde la"
    echo "función 'error'."
    echo
    echo
}


function error() {
    local parent_lineno="$1"
    local message="$2"
    local code="${3:-1}"
    echo
    if [[ -n "$message" ]] ; then
        echo "Error on or near line ${parent_lineno}: ${message}; exiting with status ${code}"
    else
        echo "Error on or near line ${parent_lineno}; exiting with status ${code}"
    fi
    error.stackTrace
    exit "${code}"
}

iargs(){
    local n="$1"
    local args="$2"
    echo "La función '${FUNCNAME[1]}' requiere $n argumentos: $args"
}

die() {
    echo "ERROR: $@"
    exit 1
    #local pid=$(ps -ef | grep -v grep | grep sintel | awk '{print $2}')
    #if [[ $pid != 0 ]]; then
    #	kill $pid
    #else
    #	return
    #fi
}

trap 'error ${LINENO}' ERR