tf-a-builder: log-splitter.py error handling

Occasionally, log-splitter fails due to the yaml format log file
contaminated by some unexpected characters.[1]
This patch will handle the exception and preserve the log file for
future investigation.

[1]: https://pastebin.linaro.org/view/3d884553

Signed-off-by: Arthur She <arthur.she@linaro.org>
Change-Id: Id686f26eed732a85ae6bb656eb7c5f0b457ef060
diff --git a/tf-a-builder/log-splitter.py b/tf-a-builder/log-splitter.py
index d47c17b..5a9c90f 100755
--- a/tf-a-builder/log-splitter.py
+++ b/tf-a-builder/log-splitter.py
@@ -49,7 +49,20 @@
         raise SystemExit("The file '{}' is not exist!!".format(plain_log))
 
     with open(plain_log, "r") as job_log:
-        log_list = yaml.load(job_log, Loader=yaml.SafeLoader)
+        try:
+            log_list = yaml.load(job_log, Loader=yaml.SafeLoader)
+        except yaml.YAMLError as exc:
+            print ("Error while parsing YAML file:")
+            if hasattr(exc, 'problem_mark'):
+                if exc.context != None:
+                    print ('  parser says\n' + str(exc.problem_mark) + '\n  ' +
+                        str(exc.problem) + ' ' + str(exc.context))
+                else:
+                    print ('  parser says\n' + str(exc.problem_mark) + '\n  ' +
+                        str(exc.problem))
+            else:
+                print ("Something went wrong while parsing yaml file")
+            sys.exit(1)
         try:
             full_test_log = "{}/{}".format(des_dir, separated_log_file["all"])
             opened_logfile["all"] = open(full_test_log, "w")
diff --git a/tf-a-builder/squad.sh b/tf-a-builder/squad.sh
index 5477c87..c6cf828 100755
--- a/tf-a-builder/squad.sh
+++ b/tf-a-builder/squad.sh
@@ -99,7 +99,7 @@
 
             resilient_cmd lavacli identities add --username ${LAVA_USER} --token ${LAVA_TOKEN} --uri "https://${LAVA_SERVER}/RPC2" default
 
-	    wait_status="$(wait_lava_job ${LAVAJOB_ID})"
+            wait_status="$(wait_lava_job ${LAVAJOB_ID})"
 
             # if timeout on waiting for LAVA to complete, create an 'artificial' lava.log indicating
             # job ID and timeout seconds
@@ -112,6 +112,8 @@
 
                 # Split the UART messages to the corresponding log files
                 ${WORKSPACE}/tf-a-job-configs/tf-a-builder/log-splitter.py "${WORKSPACE}/lava-raw.log"
+                # If there is something wrong with the log file, publish the raw log for investigation
+                [ $? -ne 0 ] && mv "${WORKSPACE}/lava-raw.log" "${WORKSPACE}/lava-raw-debug.log" && exit 1
 
                 # Fetch and store LAVA job result (1 failure, 0 success)
                 resilient_cmd lavacli jobs show ${LAVAJOB_ID} | tee "${WORKSPACE}/lava.show"