[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Revisiting Error handling (errexit)
From: |
David |
Subject: |
Re: Revisiting Error handling (errexit) |
Date: |
Tue, 5 Jul 2022 09:43:55 +1000 |
On Mon, 4 Jul 2022 at 22:22, Yair Lenga <yair.lenga@gmail.com> wrote:
> I've tried to look into a minimal
> solution that will address the most common pitfall of errexit, where many
> sequences (e.g., series of commands in a function) will not properly
> "break" with 'errexit'. For example:
>
> function foo {
> cat /missing/file # e.g.: cat non-existing file.
> action2 # Executed even if action 1 fail.
> action3
> }
>
> set -oerrexit # want to catch errors in 'foo'
> if ! foo ; then
> # Error handling for foo failure
> fi
On Tue, 5 Jul 2022 at 04:34, Yair Lenga <yair.lenga@gmail.com> wrote:
> Thanks for taking the time to review my post. I do not want to start a
> thread about the problems with ERREXIT. Instead, I'm trying to advocate for
> a minimal solution.
Here's the minimal solution that I would use.
function foo {
cat /missing/file || return 1
action2 # not executed if action 1 fail
action3 || return 2
}
foo
foo_exitstatus=$?
case "$foo_exitstatus" in
0 ) echo "no error"
;;
1 ) echo "handle first error"
;;
2 ) echo "handle a different error"
;;
esac
- Revisiting Error handling (errexit), Yair Lenga, 2022/07/04
- Re: Revisiting Error handling (errexit), Saint Michael, 2022/07/04
- Re: Revisiting Error handling (errexit), Lawrence Velázquez, 2022/07/04
- Re: Revisiting Error handling (errexit), Yair Lenga, 2022/07/04
- Re: Revisiting Error handling (errexit), Greg Wooledge, 2022/07/04
- Re: Revisiting Error handling (errexit), Lawrence Velázquez, 2022/07/04
- Re: Revisiting Error handling (errexit), Yair Lenga, 2022/07/04
- Re: Revisiting Error handling (errexit), Lawrence Velázquez, 2022/07/04
- Re: Revisiting Error handling (errexit), Yair Lenga, 2022/07/05
- Re: Revisiting Error handling (errexit), Lawrence Velázquez, 2022/07/05
- Re: Revisiting Error handling (errexit),
David <=
Re: Revisiting Error handling (errexit), Yair Lenga, 2022/07/08
Re: Revisiting Error handling (errexit), Kerin Millar, 2022/07/08
Re: Revisiting Error handling (errexit), Yair Lenga, 2022/07/08
Re: Revisiting Error handling (errexit), Greg Wooledge, 2022/07/08
Re: Revisiting Error handling (errexit), Martin D Kealey, 2022/07/08