--- a/uilib.py Fri Nov 05 12:43:25 2010 +0100
+++ b/uilib.py Fri Nov 05 14:28:07 2010 +0100
@@ -342,6 +342,16 @@
import traceback
+def exc_message(ex, encoding):
+ try:
+ return unicode(ex)
+ except:
+ try:
+ return unicode(str(ex), encoding, 'replace')
+ except:
+ return unicode(repr(ex), encoding, 'replace')
+
+
def rest_traceback(info, exception):
"""return a ReST formated traceback"""
res = [u'Traceback\n---------\n::\n']
--- a/web/views/basecontrollers.py Fri Nov 05 12:43:25 2010 +0100
+++ b/web/views/basecontrollers.py Fri Nov 05 14:28:07 2010 +0100
@@ -27,6 +27,7 @@
from cubicweb import (NoSelectableObject, ObjectNotFound, ValidationError,
AuthenticationError, typed_eid)
from cubicweb.utils import UStringIO, json, json_dumps
+from cubicweb.uilib import exc_message
from cubicweb.selectors import authenticated_user, anonymous_user, match_form_params
from cubicweb.mail import format_mail
from cubicweb.web import Redirect, RemoteCallFailed, DirectResponse
@@ -281,15 +282,15 @@
except ValueError, exc:
self.exception('error while decoding json arguments for js_%s: %s',
fname, args, exc)
- raise RemoteCallFailed(repr(exc))
+ raise RemoteCallFailed(exc_message(exc, self._cw.encoding))
try:
result = func(*args)
except (RemoteCallFailed, DirectResponse):
raise
- except Exception, ex:
+ except Exception, exc:
self.exception('an exception occurred while calling js_%s(%s): %s',
- fname, args, ex)
- raise RemoteCallFailed(repr(ex))
+ fname, args, exc)
+ raise RemoteCallFailed(exc_message(exc, self._cw.encoding))
if result is None:
return ''
# get unicode on @htmlize methods, encoded string on @jsonize methods
--- a/web/views/management.py Fri Nov 05 12:43:25 2010 +0100
+++ b/web/views/management.py Fri Nov 05 14:28:07 2010 +0100
@@ -24,7 +24,7 @@
from cubicweb.selectors import yes, none_rset, match_user_groups, authenticated_user
from cubicweb.view import AnyRsetView, StartupView, EntityView, View
-from cubicweb.uilib import html_traceback, rest_traceback
+from cubicweb.uilib import html_traceback, rest_traceback, exc_message
from cubicweb.web import formwidgets as wdgs
from cubicweb.web.formfields import guess_field
from cubicweb.web.views.schema import SecurityViewMixIn
@@ -220,15 +220,6 @@
form.render(w=w)
-def exc_message(ex, encoding):
- try:
- return unicode(ex)
- except:
- try:
- return unicode(str(ex), encoding, 'replace')
- except:
- return unicode(repr(ex), encoding, 'replace')
-
def text_error_description(ex, excinfo, req, eversion, cubes):
binfo = rest_traceback(excinfo, xml_escape(ex))
binfo += u'\n\n:URL: %s\n' % req.url()