DivestOS/Scripts
steadfasterX 7724c3effd
make divest functions error aware
this commit adds (the currently non-existing) error handling when
using divest's functions and scripts.
all the magic here gets activated when `source ../../Scripts/init.sh`
gets executed which is already a mandatory step before starting any
of the divest functions.

when something fails during patching, resetting or building
each error will be catched + printed including an error code now.
last but not least the executed file and the line number causing that
failure will be shown, too.

as all divest functions get source'd and so not a single build
script gets executed all ERR's needs to be trapped to catch issues.
I am not aware of another way to handle that properly as sourcing
means we cannot track a script or smth while this approach here
just works.

Example for an error thrown in a function call:

> ERROR: $DOS_WORKSPACE_ROOT/Scripts/Common/Functions.sh -> verifyAllPlatformTags() ended with status >1< at line >49<

Final SUCCESS result message after using `patchWorkspace`:

> [FINAL RESULT] No error detected (please check the above output nevertheless!)

Final ERROR result message after using `patchWorkspace`:

> [FINAL RESULT] Serious error(s) found!!!
> Summary error code was: 126. Check & fix all error lines above

Some notes:

- when an error occurs the process continues until the end (like it is now)
  i.e. an error will not stop the current and following tasks
- when multiple errors occur the exit codes will be summed
- buildDevice: a (summed) end result gets printed (SUCCESS or ERROR) at the very end
- the trap used to catch any error will also be active for any command executed
  on the cli. that means: type "false" -> ENTER and you will get an error, too
  same for any script exectued after source init.sh
- when all goes well the trap will be resetted at the end but there are cases
  where this might not happen -> that is why `resetEnv` can be executed to
  reset the trap, i.e. all becomes as it was before sourcing init.sh
- `resetEnv` gets called automatically:
  - after a successful `patchWorkspace` run
  - whenever CTRL+C is used (during a running task or just on the cli)
  - a process get killed (SIGHUP, TERM)
- the whole implementation might not catch all errors though - it highly depends
  on how the function or the script/program called actually handles errors or better
  said: if they return a proper exit code on failures.
  For example some tools (like some git cmds) might print an error but don't return
  a non-zero exit code. This cannot be tracked other then with your eyes or these
  must be replaced by other methods returning a non-zero exit code on failures.

Signed-off-by: steadfasterX <steadfasterX@gmail.com>
2024-04-22 10:24:18 +02:00
..
Common make divest functions error aware 2024-04-22 10:24:18 +02:00
LineageOS-14.1 Update CVE patchers 2024-04-16 08:41:35 -04:00
LineageOS-15.1 Update CVE patchers 2024-04-16 08:41:35 -04:00
LineageOS-16.0 Update CVE patchers 2024-04-16 08:41:35 -04:00
LineageOS-17.1 Update CVE patchers 2024-04-16 08:41:35 -04:00
LineageOS-18.1 Update CVE patchers 2024-04-16 08:41:35 -04:00
LineageOS-19.1 Update CVE patchers 2024-04-16 08:41:35 -04:00
LineageOS-20.0 Update CVE patchers 2024-04-16 08:41:35 -04:00
Generate_Signing_Keys.sh Tiny "fix" 2023-03-10 17:51:04 -05:00
Generate_Supporting_Files.sh Tweak 2023-05-12 21:43:27 -04:00
Generate_Verified_Boot_Hashes.sh More device additions 2023-05-10 17:20:57 -04:00
Generate_Wallpaper_Sizes.sh Fixup 2022-08-15 16:40:32 -04:00
init.sh make divest functions error aware 2024-04-22 10:24:18 +02:00
Update_Commons.sh Update commons 2024-03-05 13:07:52 -05:00