bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Error Handling with bash script


From: Marc Herbert
Subject: Re: Error Handling with bash script
Date: Wed, 26 May 2010 10:29:44 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100430 Fedora/3.0.4-2.fc12 Thunderbird/3.0.4

Le 24/05/2010 17:05, Lenga, Yair a écrit:

> I would like to propose an improvement to the bash error handling:
> Add flag/option "err_return", that will cause a user defined shell
> functions to immediately return, when a simple command will return a
> non-zero status code.
> The behavior is similar to the existing '-e', but is different in
> the following case.  Under current bash, the "Abort On Error" logic
> is suspended if the command is executed under "if", "while", "||" or
> similar. It will make it possible to implement much better error
> handling for scripts that involve user defined functions.

I agree, this looks like it could be an extremely useful feature.

The recurring and intricate discussions on this list clearly
demonstrate that "errexit":
- draws a lot of interest,
- has a broken design.

Some examples (randomly picked up among many others)
http://thread.gmane.org/gmane.comp.shells.bash.bugs/6071
http://thread.gmane.org/gmane.comp.shells.bash.bugs/12117
http://thread.gmane.org/gmane.comp.shells.bash.bugs/12281
http://thread.gmane.org/gmane.comp.shells.bash.bugs/13726
http://thread.gmane.org/gmane.comp.shells.bash.bugs/13465


Since "errexit" is hopelessly caught forever in design by committee
and backward compatibility traps, a brand new "errreturn" feature
could provide something useful instead.

This is basically about some very minimal, poor-man's exceptions. An
extremely basic feature to stop code running wild when something
unexpected and bad happens. Only prehistoric or low-level, operating
systems languages like C miss such a feature.


> Adding error handling to this script can be done in two ways:
> 1 - Modifying each functions/script:
> Function f1 {
>       cp /new/data /current/data || return 1
>       step1                      || return 1
>       step2                      || return 1
> }

I find this slightly better:
Function f1 {
      cp /new/data /current/data || return $?
        step1                      || return $?
        step2                      || return $?
}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]