Browse Source

Return informative exit status from jat__sfinish()

Alois Mahdal 6 years ago
parent
commit
ba77411e50
1 changed files with 17 additions and 0 deletions
  1. 17
    0
      src/jat.sh.skel

+ 17
- 0
src/jat.sh.skel View File

@@ -494,10 +494,12 @@ jat__sfinish() {
494 494
     # leftover session and whole log will be merged.
495 495
     #
496 496
     local fileas    # session id for filing in 'finished' folder
497
+    local es        # final exit status
497 498
     test -d "$JAT__DIR/session" || {
498 499
         __jat__show_error "no active session: no $JAT__DIR/session"
499 500
         return 2
500 501
     }
502
+    es=$(__jat__final_es)
501 503
     __jat__show_sfinish
502 504
     __jat__log_event SINFO "finishing session"
503 505
     __jat__writelog <<<"finalized: true"
@@ -507,6 +509,7 @@ jat__sfinish() {
507 509
     mv "$JAT__DIR/session" "$JAT__DIR/finished/$fileas"
508 510
     rm -f "$JAT__DIR/last"
509 511
     ln -s "finished/$fileas" "$JAT__DIR/last"
512
+    return "$es"
510 513
 }
511 514
 
512 515
 jat__log_error() {
@@ -823,6 +826,20 @@ __jat__es_match() {
823 826
     return 1
824 827
 }
825 828
 
829
+__jat__final_es() {
830
+    #
831
+    # Print final exit status
832
+    #
833
+    # Roughly follows TFKit's semantic; unoffical link:
834
+    #
835
+    #     https://github.com/AloisMahdal/shellfu/tree/master/utils/tfkit/doc
836
+    #
837
+    test "$(jat__stat serrc)"  -gt 0 && echo 4 && return
838
+    test "$(jat__stat swarc)"  -gt 0 && echo 3 && return
839
+    test "$(jat__stat sfailc)" -gt 0 && echo 1 && return
840
+    echo 0
841
+}
842
+
826 843
 __jat__log_event() {
827 844
     #
828 845
     # Pass YAML log event to __jat__writelog()