Remix.run Logo
xelxebar 2 days ago

I kind of feel like set -o errexit (i.e. set -e) provides enough unexpected semantics that explicit error handling makes more sense. One thing that often trips people up is this:

    set -e
    [ -f nonexistent ] && do_something
    echo 'this line runs'
but

    set -e
    f(){ [ -f nonexistent ] && do_something; }
    f
    echo 'This line does not run'
modulo some version differences.
chubot 2 days ago | parent [-]

Yup, that is pitfall 8 here - https://oils.pub/release/latest/doc/error-handling.html#list...

I think I got that from the Wooledge Wiki

Explicit error handling seems fine in theory, and of course you can use that style with OSH if you want

But in practice, set -e seems more common. For example, Alpine Linux abuild is a big production shell script, and they gradually switched to set -e

(really, you're damned if you do, and damned if you don't, so that is a big reason YSH exists)