Permalink
Browse files

Added 'config' to tornadorpc, now prints errors if tornadorpc.config.…

…verbose == True (default) and prints short errors if tornadorpc.config.short_errors == True (default)

git-svn-id: http://tornadorpc.googlecode.com/svn/trunk@5 6a0cc88c-bc38-11de-9a73-11f8458f6c97
  • Loading branch information...
1 parent 1776bf4 commit de5ad4747a5a780bcc839b530f02385c17e3d184 catchjosh committed Oct 20, 2009
Showing with 31 additions and 3 deletions.
  1. +1 −1 tornadorpc/__init__.py
  2. +30 −2 tornadorpc/base.py
View
2 tornadorpc/__init__.py
@@ -13,4 +13,4 @@
limitations under the License.
"""
-from base import private, start_server
+from base import private, start_server, config
View
32 tornadorpc/base.py
@@ -24,6 +24,13 @@
from tornado.web import RequestHandler
import types
+# Configuration element
+class Config(object):
+ verbose = True
+ short_errors = True
+
+config = Config()
+
class BaseRPCParser(object):
"""
This class is responsible for managing the request, dispatch,
@@ -111,6 +118,7 @@ def dispatch(self, method_name, params):
return self.faults.invalid_params()
except:
# We should log here...bare excepts are evil.
+ self.traceback(method_name, params)
return self.faults.internal_error()
return response
elif type(params) in (types.ListType, types.TupleType):
@@ -121,13 +129,33 @@ def dispatch(self, method_name, params):
return self.faults.invalid_params()
except:
# Once again, we need to log here
+ self.traceback(method_name, params)
return self.faults.internal_error()
return response
else:
# Bad argument formatting?
return self.faults.invalid_params()
- def parse_request(self, request_body):
+ def traceback(self, method_name, params):
+ import traceback
+ err_lines = traceback.format_exc().splitlines()
+ err_title = "ERROR IN %s" % method_name
+ if len(params) > 0:
+ err_title += ' - (PARAMS: %s)' % params
+ err_sep = ('-'*len(err_title))[:79]
+ err_lines = [err_sep, err_title, err_sep]+err_lines
+ global config
+ if config.verbose == True:
+ if len(err_lines) >= 7 and config.short_errors:
+ # Minimum number of lines to see what happened
+ # Plust title and separators
+ print '\n'.join(err_lines[0:4]+err_lines[-3:])
+ else:
+ print '\n'.join(err_lines)
+ # Log here
+ return
+
+ def parse_requesr(self, request_body):
"""
Extend this on the implementing protocol. If it
should error out, return the output of the
@@ -173,7 +201,7 @@ class BaseRPCHandler(RequestHandler):
BaseRPCParser above.
"""
_RPC_ = None
-
+
def post(self):
# Very simple -- dispatches request body to the parser
# and returns the output

0 comments on commit de5ad47

Please sign in to comment.