AOSC-Archive / autobuild3

AOSC OS package maintenance toolkit (version 3)
https://aosc.io
GNU General Public License v2.0
24 stars 17 forks source link

Fix error handling for custom build scripts #100

Open Artoria2e5 opened 7 years ago

Artoria2e5 commented 7 years ago

Our current error handling for sourced scripts involve testing what is returned from the script itself. For predefined build scripts this works well because we have many return-on-error hooks, but things go wild with poorly-written (read: every single one of) autobuild/build scripts.

We can either fix all the scripts, or at least partially switch to some "strict mode" handling by set -ueE and trap something ERR. (Hell, I don't even like how .() messes up scopes in the first place.) It is, however, still important to note that set -e does not properly handle lines with && and/or ||. And I also have no idea about how to re-enter the script from an error handler.

LionNatsu commented 6 years ago

https://github.com/AOSC-Dev/autobuild3/blob/a471ed6fbeccacbaba351ff307e57196ab4a93c9/build/00-self.sh#L10-L16

Is this a hook?

Artoria2e5 commented 6 years ago

Yes, it is. See https://github.com/AOSC-Dev/autobuild3/blob/d146b34/proc/50-build_exec.sh#L6-L25.

LionNatsu commented 6 years ago

https://github.com/AOSC-Dev/autobuild3/blob/d146b34acfd90ad1b02579c47c6c4e306523c245/proc/50-build_exec.sh#L27

Looks good, but why do ABTYPE=self never exit when errors occur?

For example, autobuild/build:

false
echo It should not be here

Is it because set -e cannot work properly in this scope?

Artoria2e5 commented 6 years ago

We have a set -e ???????

LionNatsu commented 6 years ago

arch_loadfile_strict have.

Artoria2e5 commented 6 years ago

It's probably the || thing that is breaking set -e here. Perhaps it should be rewritten into an explicit if (($?)); then ...