Commit 452178ae authored by Casey Duncan's avatar Casey Duncan

Improved error output for xmlrpc faults

 - Value is stripped of HTML tags and minimally formatted

 - In debug mode, a full traceback is included in the fault string
parent 469966dc
...@@ -19,6 +19,7 @@ See http://www.xmlrpc.com/ and http://linux.userland.com/ for more ...@@ -19,6 +19,7 @@ See http://www.xmlrpc.com/ and http://linux.userland.com/ for more
information about XML-RPC and Zope. information about XML-RPC and Zope.
""" """
import re
import sys, types import sys, types
from HTTPResponse import HTTPResponse from HTTPResponse import HTTPResponse
import xmlrpclib import xmlrpclib
...@@ -65,8 +66,6 @@ def parse_input(data): ...@@ -65,8 +66,6 @@ def parse_input(data):
# r.__dict__.update(anHTTPResponse.__dict__) # r.__dict__.update(anHTTPResponse.__dict__)
# return r # return r
######################################################################## ########################################################################
# Possible implementation helpers: # Possible implementation helpers:
...@@ -129,18 +128,31 @@ class Response: ...@@ -129,18 +128,31 @@ class Response:
and issubclass(t, Unauthorized)): and issubclass(t, Unauthorized)):
return self._real.exception(fatal=fatal, info=info) return self._real.exception(fatal=fatal, info=info)
# Create an appropriate Fault object. Unfortunately, we throw away # Create an appropriate Fault object. Containing error information
# most of the debugging information. More useful error reporting is
# left as an exercise for the reader.
Fault=xmlrpclib.Fault Fault=xmlrpclib.Fault
f=None f=None
try: try:
# Strip HTML tags and format the error value
v = str(v)
v = re.sub(r"<br\s*/?>", "\n", v)
remove = [r"<[^<>]*>", r"&[A-Za-z]+;"]
for pat in remove:
v = re.sub(pat, " ", v)
v = re.sub(r"\n(?:\s*\n)+", "\n\n", v)
from Globals import DevelopmentMode
if DevelopmentMode:
from traceback import format_exception
value = ''.join(format_exception(t, v, tb))
else:
value = '%s\n\n%s' % (t, v)
if isinstance(v, Fault): if isinstance(v, Fault):
f=v f=v
elif isinstance(v, Exception): elif isinstance(v, Exception):
f=Fault(-1, "Unexpected Zope exception: " + str(v)) f=Fault(-1, 'Unexpected Zope exception: %s' % value)
else: else:
f=Fault(-2, "Unexpected Zope error value: " + str(v)) f=Fault(-2, 'Unexpected Zope error value: %s' % value)
except: except:
f=Fault(-3, "Unknown Zope fault type") f=Fault(-3, "Unknown Zope fault type")
......
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