~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to lib/common/util.py

  • Committer: mattgiuca
  • Date: 2008-02-22 00:53:35 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:540
Refactored error handling and reporting. Much friendlier error messages, for
both developers and users.

Note that PythonDebug is now going to be ignored. IVLE itself selects when to
display a traceback. (So IVLE will display tracebacks even in a production
environment, for internal server errors).

common/util.py: Added class IVLEError, which is now used for throwing
user-readable errors inside IVLE instead of throwing apache SERVER_RETURN
exceptions.

dispatch/request: throw_error now throws an IVLEError instead of a
SERVER_RETURN. It also takes a new argument, "message", which can be used to
place an optional message inside the exception which will be displayed to the
user.
Finally, added a method get_http_codename which returns the name and
description of common HTTP error codes. (Used to report errors which don't
have a message supplied).

dispatch/__init__: Added a wrapper around handler which catches all exceptions
thrown out of IVLE.
The handler for this selectively handles exceptions.
4xx level exceptions thrown are user errors, so these are reported in a very
friendly way, with no traceback, and in the familiar IVLE environment.
5xx level exceptions and any other exceptions are reported in a minimal
environment (to avoid cascading errors) with a traceback and a request for the
user to report it to the administrators.

As many calls to req.throw_error as possible should now have a message
included, to make identifying errors easier.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
root_dir = conf.root_dir
33
33
 
 
34
class IVLEError(Exception):
 
35
    """
 
36
    This is the "standard" exception class for IVLE errors.
 
37
    It is the ONLY exception which should propagate to the top - it will then
 
38
    be displayed to the user as an HTTP error with the given code.
 
39
 
 
40
    All other exceptions are considered IVLE bugs and should not occur
 
41
    (they will display a traceback).
 
42
 
 
43
    This error should not be raised directly. Call req.throw_error.
 
44
    """
 
45
    def __init__(self, httpcode, message=None):
 
46
        self.httpcode = httpcode
 
47
        self.message = message
 
48
        self.args = (httpcode, message)
 
49
 
34
50
def make_path(path):
35
51
    """Given a path relative to the IVLE root, makes the path relative to the
36
52
    site root using conf.root_dir. This path can be used in URLs sent to the