Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Skip to content
Commit 488dd4db authored by Yi-Yo Chiang's avatar Yi-Yo Chiang
Browse files

adb-remount-test: Harden error handling and fix typo

Remove the ERR trap handler as it doesn't work as intended and is rather
finicky. (Read more: mywiki.wooledge.org/BashFAQ/105)

Trap ERR (and set -e) could be an useful tool if applied sparingly, like
in a subshell, but they seem almost useless, even harmful, if applied
globally due to the following reasons.

The problems it brings includes but not limited to:
* ERR trap handler doesn't propagate inside subshells and functions.
  This makes it rather useless for reporting unchecked errors.
* Set '-o errtrace' kind of fixes previous issue, but it would report
  superfluous errors, because as the non-zero error code propagates up
  the call stack, each subshell expression would evaluate to non-zero
  status, repeatedly triggering the trap handler.
* Breaks the rather common "execute comand and check ${?}" pattern in
  this script, for example:
    H=$(adb remount)
    [ "${?}" != 0 ] && echo warning....
  script would prematurely exit if $(adb remount) fails, not having a
  chance to recover from error.
--

`expr ...` is problematic because it exits with non-zero status if the
calculated result is zero. This makes ordinary harmless looking
expressions, which evaluates perfectly fine, to exit with error status
  A=$(expr 1 + 1)  # $? = 0
  A=$(expr 1 - 1)  # $? = 1
Just replace all `expr` with the more robust `$(( ... ))` construct.
--

Also fix typo scratch_paritition -> scratch_partition.

Bug: 243116800
Test: adb-remount-test.sh
Change-Id: I2a8941341a7a12359896f0e08ecd21766396eb45
parent aa46531f
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment