Skip to contentSkip to conversation

report-error: Add a check for binary log file

PATCH In review Michael Wood 2 participants 4 messages Jan 29, 2015 – Feb 3, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 report-error: Add a check for binary log file

Check to see if the log file is a binary. If it is do not try to submit it in our error-report.

[YOCTO #7263]

---
 meta/classes/report-error.bbclass | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
meta/classes/report-error.bbclass +16 -1
index 8b30422..101fe9b 100644
@@ -24,6 +24,15 @@ def errorreport_savedata(e, newdata, file):
         json.dump(newdata, f, indent=4, sort_keys=True)
     return datafile
 
+def errorreport_testlogforbinary(data):
+    for c in data:
+      # If the data contains non visible character below 10 it's a binary
+      if (ord(c) < 10):
+        return True
+
+    return False
+
+
 python errorreport_handler () {
         import json
 
@@ -48,7 +57,13 @@ python errorreport_handler () {
             taskdata['task'] = task
             if log:
                 logFile = open(log, 'r')
-                taskdata['log'] = logFile.read()
+                # Detect binary log output
+                logdata = logFile.read()
+                if  errorreport_testlogforbinary(logdata):
+                    taskdata['log'] = "Log in binary format"
+                else:
+                    taskdata['log'] = logdata
+
                 logFile.close()
             else:
                 taskdata['log'] = "No Log"
Signature · 1 line
2.1.0
#1 lore raw
Quoted 35 lines · Michael Wood

Check to see if the log file is a binary. If it is do not try to submit it in our error-report.

[YOCTO #7263]

---
 meta/classes/report-error.bbclass | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
meta/classes/report-error.bbclass +9 -1
index 8b30422..101fe9b 100644
@@ -24,6 +24,15 @@ def errorreport_savedata(e, newdata, file):
         json.dump(newdata, f, indent=4, sort_keys=True)
     return datafile
 
+def errorreport_testlogforbinary(data):
+    for c in data:
+      # If the data contains non visible character below 10 it's a binary
+      if (ord(c) < 10):
+        return True
+
+    return False
+
+
 python errorreport_handler () {
         import json
 
@@ -48,7 +57,13 @@ python errorreport_handler () {
             taskdata['task'] = task
             if log:
                 logFile = open(log, 'r')
-                taskdata['log'] = logFile.read()

meta/classes/report-error.bbclass python errorreport_handler () { · line 69

Quoted 10 lines
meta/classes/report-error.bbclass +7 -0
+                # Detect binary log output
+                logdata = logFile.read()
+                if  errorreport_testlogforbinary(logdata):
+                    taskdata['log'] = "Log in binary format"
+                else:
+                    taskdata['log'] = logdata
+
                 logFile.close()
             else:
                 taskdata['log'] = "No Log"

I was thinking about this a bit more. How about we put a try/except around the json code which sets taskdata['log'] = "Log in binary format" if the original coding doesn't work for any reason? That way we should catch any problem with the log?

Cheers,

Richard

#2 lore raw

PATCH 1/1 report-error: Catch un-readable log data

If a log data cannot be decoded to utf-8 or read then handle this gracefully. This can happen if a log file contains binary or something goes wrong with the file read process.

---
 meta/classes/report-error.bbclass | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
meta/classes/report-error.bbclass +5 -1
index 8b30422..750042b 100644
@@ -48,7 +48,11 @@ python errorreport_handler () {
             taskdata['task'] = task
             if log:
                 logFile = open(log, 'r')
-                taskdata['log'] = logFile.read()
+                try:
+                    taskdata['log'] = logFile.read().decode('utf-8')
+                except:
+                    taskdata['log'] = "Unable to read log file"
+
                 logFile.close()
             else:
                 taskdata['log'] = "No Log"
Signature · 1 line
2.1.0
#3 lore raw

PATCH v2 1/1 report-error: Catch un-readable log data

If a log data cannot be decoded to utf-8 or read then handle this gracefully. This can happen if a log file contains binary or something goes wrong with the file open process.

---
 meta/classes/report-error.bbclass | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
meta/classes/report-error.bbclass +7 -3
index 8b30422..5f155e3 100644
@@ -47,9 +47,13 @@ python errorreport_handler () {
             taskdata['package'] = e.data.expand("${PF}")
             taskdata['task'] = task
             if log:
-                logFile = open(log, 'r')
-                taskdata['log'] = logFile.read()
-                logFile.close()
+                try:
+                    logFile = open(log, 'r')
+                    taskdata['log'] = logFile.read().decode('utf-8')
+                    logFile.close()
+                except:
+                    taskdata['log'] = "Unable to read log file"
+
             else:
                 taskdata['log'] = "No Log"
             jsondata = json.loads(errorreport_getdata(e))
Signature · 1 line
2.1.0