Skip to content

Commit 8b8e5ae

Browse files
committed
Merge branch 'rapp_cognitive_exercise_error_reporting' into devel (closes #344)
* rapp_cognitive_exercise_error_reporting: adds traceback error reporting on rapp_cognitive_exercises services
2 parents a7ee0b9 + f9a6f1d commit 8b8e5ae

7 files changed

+30
-15
lines changed

rapp_cognitive_exercise/src/cognitive_test_creator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import os
2626
import sys
2727
from app_error_exception import AppError
28+
from helper_functions import CognitiveExerciseHelperFunctions
2829

2930
from rapp_platform_ros_communications.srv import (
3031
cognitiveTestCreatorSrv,
@@ -203,10 +204,12 @@ def testCreator(self,req):
203204
except IndexError:
204205
#print "test "+fname +" is broken"
205206
res.error="IndexError.. test "+fname +" is broken"
207+
CognitiveExerciseHelperFunctions.traceError(res.error,res.trace)
206208
res.success=False
207209
except IOError:
208210
#print "IO Error, cannot open test file or write xml file"
209211
res.error="IO Error, cannot open test file or write xml file"
212+
CognitiveExerciseHelperFunctions.traceError(res.error,res.trace)
210213
res.success=False
211214
except AppError as e:
212215
AppError.passErrorToRosSrv(e,res)

rapp_cognitive_exercise/src/helper_functions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from os.path import expanduser
77
from collections import OrderedDict
88
from app_error_exception import AppError
9+
import traceback
910

1011
from rapp_platform_ros_communications.srv import (
1112
ontologySubSuperClassesOfSrv,
@@ -185,3 +186,16 @@ def organizeUserPerformanceByTimestamp(userPerf):
185186
userPerfOrganizedByTimestamp[int(userPerf.timestamps[i])]=[tlist]
186187
userPerfOrganizedByTimestamp=OrderedDict(sorted(userPerfOrganizedByTimestamp.items(), key=lambda t: t[0], reverse=True)) #Order is descending
187188
return userPerfOrganizedByTimestamp
189+
190+
@staticmethod
191+
## @brief Traces and returns the code line where an error occured
192+
# @param error [String] the error occured
193+
# @param trace [list] the execution messages trace list
194+
#
195+
# @param trace [list] the execution messages trace list
196+
def traceError(error,trace):
197+
for frame in traceback.extract_tb(sys.exc_info()[2]):
198+
fname,lineno,fn,text = frame
199+
print "Error in %s on line %d" % (fname, lineno)
200+
error = error + "Error in %s on line %d" % (fname, lineno)
201+
trace.append("Error in %s on line %d" % (fname, lineno))

rapp_cognitive_exercise/src/recordUserCognitiveTestPerformance.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,17 @@ def recordPerformance(self,req):
6363
res.trace.append("IndexError: " +str(e))
6464
res.error="IndexError: "+str(e)
6565
res.success=False
66+
CognitiveExerciseHelperFunctions.traceError(res.error,res.trace)
6667
except IOError, e:
6768
res.success=False
6869
res.trace.append("IOError: "+str(e))
6970
res.error="IOError: "+str(e)
71+
CognitiveExerciseHelperFunctions.traceError(res.error,res.trace)
7072
except KeyError, e:
7173
res.success=False
7274
res.trace.append('"KeyError (probably invalid cfg/.yaml parameter) "%s"' % str(e))
7375
res.error='"KeyError (probably invalid cfg/.yaml parameter) "%s"' % str(e)
76+
CognitiveExerciseHelperFunctions.traceError(res.error,res.trace)
7477
except AppError as e:
7578
AppError.passErrorToRosSrv(e,res)
7679
return res

rapp_cognitive_exercise/src/returnTestsOfTypeSubtypeDiffuclty.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,17 @@ def returnTestsFunction(self,req):
9292
res.trace.append("IndexError: " +str(e))
9393
res.error="IndexError: "+str(e)
9494
res.success=False
95+
CognitiveExerciseHelperFunctions.traceError(res.error,res.trace)
9596
except IOError, e:
9697
res.success=False
9798
res.trace.append("IOError: "+str(e))
9899
res.error="IOError: "+str(e)
100+
CognitiveExerciseHelperFunctions.traceError(res.error,res.trace)
99101
except KeyError, e:
100102
res.success=False
101103
res.trace.append('"KeyError (probably invalid cfg/.yaml parameter) "%s"' % str(e))
102104
res.error='"KeyError (probably invalid cfg/.yaml parameter) "%s"' % str(e)
105+
CognitiveExerciseHelperFunctions.traceError(res.error,res.trace)
103106
except AppError as e:
104107
AppError.passErrorToRosSrv(e,res)
105108
res.totalNumberOfTestsReturned=0

rapp_cognitive_exercise/src/test_selector.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import rospkg
2222
import rospy
2323
import sys
24-
import traceback
2524
import xml.etree.ElementTree as ET
2625
import calendar
2726
import time
@@ -98,21 +97,17 @@ def chooserFunction(self,req):
9897
res.trace.append("IndexError: " +str(e))
9998
res.error="IndexError: "+str(e)
10099
res.success=False
100+
CognitiveExerciseHelperFunctions.traceError(res.error,res.trace)
101101
except IOError, e:
102102
res.success=False
103103
res.trace.append("IOError: "+str(e))
104104
res.error="IOError: "+str(e)
105+
CognitiveExerciseHelperFunctions.traceError(res.error,res.trace)
105106
except KeyError, e:
106107
res.success=False
107108
res.trace.append('"KeyError (probably invalid cfg/.yaml parameter) "%s"' % str(e))
108109
res.error='"KeyError (probably invalid cfg/.yaml parameter) "%s"' % str(e)
109-
print "KeyError Exception. Tracing..."
110-
self.traceError(res.error,res.trace)
111-
#for frame in traceback.extract_tb(sys.exc_info()[2]):
112-
#fname,lineno,fn,text = frame
113-
#print "Error in %s on line %d" % (fname, lineno)
114-
#res.error = res.error + "Error in %s on line %d" % (fname, lineno)
115-
#res.trace.append("Error in %s on line %d" % (fname, lineno))
110+
CognitiveExerciseHelperFunctions.traceError(res.error,res.trace)
116111
except AppError as e:
117112
AppError.passErrorToRosSrv(e,res)
118113
return res
@@ -404,10 +399,3 @@ def loadParamDifficultyModifiersAndHistorySettings(self):
404399
pastTests = int(rospy.get_param('rapp_cognitive_test_selector_past_performance_number_of_past_tests'))
405400
lookBackTimeStamp=pastMonths*30*24*3600
406401
return difficultyModifier1to2,difficultyModifier2to3,historyBasedOnNumOfTestsAndNotTime,pastMonths,pastTests,lookBackTimeStamp
407-
408-
def traceError(self,error,trace):
409-
for frame in traceback.extract_tb(sys.exc_info()[2]):
410-
fname,lineno,fn,text = frame
411-
print "Error in %s on line %d" % (fname, lineno)
412-
error = error + "Error in %s on line %d" % (fname, lineno)
413-
trace.append("Error in %s on line %d" % (fname, lineno))

rapp_cognitive_exercise/src/userScoreHistoryForAllCategories.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ def returnUserHistory(self,req):
6363
res.trace.append("ValueError: " +str(e))
6464
res.error="ValueError: "+str(e)
6565
res.success=False
66+
CognitiveExerciseHelperFunctions.traceError(res.error,res.trace)
6667
except IndexError, e:
6768
res.trace.append("IndexError: " +str(e))
6869
res.error="IndexError: "+str(e)
6970
res.success=False
71+
CognitiveExerciseHelperFunctions.traceError(res.error,res.trace)
7072
except AppError as e:
7173
AppError.passErrorToRosSrv(e,res)
7274
return res

rapp_cognitive_exercise/src/userScoresForAllCategories.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ def returnUserScores(self,req):
5555
res.trace.append("ValueError: " +str(e))
5656
res.error="ValueError: "+str(e)
5757
res.success=False
58+
CognitiveExerciseHelperFunctions.traceError(res.error,res.trace)
5859
except IndexError, e:
5960
res.trace.append("IndexError: " +str(e))
6061
res.error="IndexError: "+str(e)
6162
res.success=False
63+
CognitiveExerciseHelperFunctions.traceError(res.error,res.trace)
6264
except AppError as e:
6365
AppError.passErrorToRosSrv(e,res)
6466
return res

0 commit comments

Comments
 (0)