Commit 154190b3 authored by Vincent Pelletier's avatar Vincent Pelletier

Simplify activity error path.

 - Move try..finaly block in Message.__call__ to contain all code executed after security context is changed.
 - Raise an error in Message.__call__ when method is not found.
 - Raise a dummy exception in Message.setExecutionState when there is no previous exception nor any given exception. This allows handling both cases in a single way.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@24104 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a376ba40
...@@ -248,11 +248,13 @@ class Message: ...@@ -248,11 +248,13 @@ class Message:
# Change user if required (TO BE DONE) # Change user if required (TO BE DONE)
# We will change the user only in order to execute this method # We will change the user only in order to execute this method
user = self.changeUser(self.user_name, activity_tool) user = self.changeUser(self.user_name, activity_tool)
# XXX: There is no check to see if user is allowed to access
# that method !
method = getattr(obj, self.method_id, None)
try: try:
if method is None: try:
# XXX: There is no check to see if user is allowed to access
# that method !
method = obj.unrestrictedTraverse(self.method_id)
except AttributeError:
method = None
self.setExecutionState(MESSAGE_NOT_EXECUTABLE, context=activity_tool) self.setExecutionState(MESSAGE_NOT_EXECUTABLE, context=activity_tool)
else: else:
result = method(*self.args, **self.kw) result = method(*self.args, **self.kw)
...@@ -353,21 +355,22 @@ Exception: %s %s ...@@ -353,21 +355,22 @@ Exception: %s %s
if is_executed != MESSAGE_EXECUTED: if is_executed != MESSAGE_EXECUTED:
if exc_info is None: if exc_info is None:
exc_info = sys.exc_info() exc_info = sys.exc_info()
if exc_info == (None, None, None):
# Raise a dummy exception, ignore it, fetch it and use it as if it was the error causing message non-execution. This will help identifyting the cause of this misbehaviour.
try:
raise Exception, 'Message execution failed, but there is no exception to explain it. This is a dummy exception so that one can track down why we end up here outside of an exception handling code path.'
except:
pass
exc_info = sys.exc_info()
if log: if log:
LOG('ActivityTool', WARNING, 'Could not call method %s on object %s. Activity created at:\n%s' % (self.method_id, self.object_path, self.call_traceback), error=exc_info) LOG('ActivityTool', WARNING, 'Could not call method %s on object %s. Activity created at:\n%s' % (self.method_id, self.object_path, self.call_traceback), error=exc_info)
# push the error in ZODB error_log # push the error in ZODB error_log
error_log = getattr(context, 'error_log', None) error_log = getattr(context, 'error_log', None)
if error_log is not None: if error_log is not None:
error_log.raising(1) error_log.raising(exc_info)
if exc_info == (None, None, None):
if format_list is not None:
self.traceback = ''.join(format_list(extract_stack()[:-1]))
else:
self.traceback = ''
else:
self.traceback = ''.join(ExceptionFormatter.format_exception(*exc_info))
self.exc_type = exc_info[0] self.exc_type = exc_info[0]
self.exc_value = str(exc_info[1]) self.exc_value = str(exc_info[1])
self.traceback = ''.join(ExceptionFormatter.format_exception(*exc_info))
def getExecutionState(self): def getExecutionState(self):
return self.is_executed return self.is_executed
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment