| |
- Singleton
- WebKit.Object.Object(__builtin__.object, MiscUtils.NamedValueAccess.NamedValueAccess)
-
- ExceptionHandler
class ExceptionHandler(WebKit.Object.Object) |
|
Exception handling.
ExceptionHandler is a utility class for Application that is created
to handle a particular exception. The object is a one-shot deal.
After handling an exception, it should be removed.
At some point, the exception handler sends
`writeExceptionReport` to the transaction (if present), which
in turn sends it to the other transactional objects
(application, request, response, etc.) The handler is the
single argument for this message.
Classes may find it useful to do things like this::
exceptionReportAttrs = 'foo bar baz'.split()
def writeExceptionReport(self, handler):
handler.writeTitle(self.__class__.__name__)
handler.writeAttrs(self, self.exceptionReportAttrs)
The handler write methods that may be useful are:
* write
* writeTitle
* writeDict
* writeAttrs
Derived classes must not assume that the error occured in a
transaction. self._tra may be None for exceptions outside
of transactions.
**HOW TO CREATE A CUSTOM EXCEPTION HANDLER**
In the ``__init__.py`` of your context::
from WebKit.ExceptionHandler import ExceptionHandler as _ExceptionHandler
class ExceptionHandler(_ExceptionHandler):
_hideValuesForFields = _ExceptionHandler._hideValuesForFields + ['foo', 'bar']
def work(self):
_ExceptionHandler.work(self)
# do whatever
# override other methods if you like
def contextInitialize(app, ctxPath):
app._exceptionHandlerClass = ExceptionHandler
You can also control the errors with settings in
``Application.config`` |
|
- Method resolution order:
- ExceptionHandler
- WebKit.Object.Object
- __builtin__.object
- MiscUtils.NamedValueAccess.NamedValueAccess
Methods defined here:
- __init__(self, application, transaction, excInfo, formatOptions=None)
- Create an exception handler instance.
ExceptionHandler instances are created anew for each exception.
Instantiating ExceptionHandler completes the process --
the caller need not do anything else.
- basicServletName(self)
- The base name for the servlet (sans directory).
- emailException(self, htmlErrMsg)
- Email the exception.
Emails the exception, either as an attachment,
or in the body of the mail.
- errorPageFilename(self)
- Create filename for error page.
Construct a filename for an HTML error page, not including the
``ErrorMessagesDir`` setting (which `saveError` adds on).
- filterDictValue(self, value, key, dict)
- Filter dictionary values.
Filters keys from a dict. Currently ignores the
dictionary, and just filters based on the key.
- filterValue(self, value, key)
- Filter values.
This is the core filter method that is used in all filtering.
By default, it simply returns self._hiddenString if the key is
in self._hideValuesForField (case insensitive). Subclasses
could override for more elaborate filtering techniques.
- htmlDebugInfo(self)
- Return the debug info.
Return HTML-formatted debugging information about the current exception.
Calls `writeHTML`, which uses ``self.write(...)`` to add content.
- logExceptionToConsole(self, stderr=None)
- Log an exception.
Logs the time, servlet name and traceback to the console
(typically stderr). This usually results in the information
appearing in console/terminal from which AppServer was launched.
- logExceptionToDisk(self, errorMsgFilename=None)
- Log the exception to disk.
Writes a tuple containing (date-time, filename,
pathname, exception-name, exception-data,error report
filename) to the errors file (typically 'Errors.csv')
in CSV format. Invoked by `handleException`.
- privateErrorPage(self)
- Return a private error page.
Returns an HTML page intended for the developer with
useful information such as the traceback.
Most of the contents are generated in `htmlDebugInfo`.
- publicErrorPage(self)
- Return a public error page.
Returns a brief error page telling the user that an error has occurred.
Body of the message comes from ``UserErrorMessage`` setting.
- repr(self, value)
- Get HTML encoded representation.
Returns the repr() of value already HTML encoded. As a special case,
dictionaries are nicely formatted in table.
This is a utility method for `writeAttrs`.
- saveErrorPage(self, html)
- Save the error page.
Saves the given HTML error page for later viewing by
the developer, and returns the filename used.
- servletPathname(self)
- The full filesystem path for the servlet.
- setting(self, name)
- Settings are inherited from Application.
- work(self)
- Main error handling method.
Invoked by `__init__` to do the main work. This calls
`logExceptionToConsole`, then checks settings to see if it should
call `saveErrorPage` (to save the error to disk) and `emailException`.
It also sends gives a page from `privateErrorPage` or
`publicErrorPage` (which one based on ``ShowDebugInfoOnErrors``).
- write(self, s)
- Output `s` to the body.
- writeAttrs(self, obj, attrNames)
- Output object attributes.
Writes the attributes of the object as given by attrNames.
Tries ``obj._name` first, followed by ``obj.name()``.
Is resilient regarding exceptions so as not to spoil the
exception report.
- writeDict(self, d, heading=None, encoded=None)
- Output a table-formated dictionary.
- writeEnvironment(self)
- Output environment.
Writes the environment this is being run in. This is *not* the
environment that was passed in with the request (holding the CGI
information) -- it's just the information from the environment
that the AppServer is being executed in.
- writeFancyTraceback(self)
- Output a fancy traceback, using cgitb.
- writeHTML(self)
- Write the traceback.
Writes all the parts of the traceback, invoking:
* `writeTraceback`
* `writeMiscInfo`
* `writeTransaction`
* `writeEnvironment`
* `writeIds`
* `writeFancyTraceback`
- writeIds(self)
- Output OS identification.
Prints some values from the OS (like processor ID).
- writeMiscInfo(self)
- Output misc info.
Write a couple little pieces of information about the environment.
- writeTitle(self, s)
- Output the sub-heading to define a section.
- writeTraceback(self)
- Output the traceback.
Writes the traceback, with most of the work done
by `WebUtils.HTMLForException.HTMLForException`.
- writeTransaction(self)
- Output transaction.
Lets the transaction talk about itself, using
`Transaction.writeExceptionReport`.
- writeln(self, s)
- Output `s` plus a newline.
Methods inherited from WebKit.Object.Object:
- deprecated(self, method)
- Output a deprecation warning.
The implementation of WebKit sometimes invokes this method which prints
a warning that the method you are using has been deprecated.
This method expects that deprecated methods say so at the beginning of
their doc string and terminate that msg with @. For example:
DEPRECATED: Class.foo() on 01/24/01 in ver 0.5. Use Class.bar() instead. @
Putting this information in the doc string is important for accuracy
in the generated docs.
Example call:
self.deprecated(self.foo)
Data descriptors inherited from WebKit.Object.Object:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Methods inherited from MiscUtils.NamedValueAccess.NamedValueAccess:
- handleUnknownSetKey(self, key)
- hasValueForKey(self, key)
- Check whether key is available.
Returns true if the key is available, although that does not guarantee
that there will not be errors caused by retrieving the key.
- hasValueForName(self, keysString)
- Check whether name is available.
- resetKeyBindings(self)
- Rest all key bindings, releasing alreaedy referenced values.
- setValueForKey(self, key, value)
- Set value for a given key.
Suppose key is 'foo'.
This method sets the value with the following precedence:
1. Public attributes before private attributes
2. Methods before non-methods
More specifically, this method then uses one of the following:
@@ 2000-03-04 ce: fill in
... or invokes handleUnknownSetKey().
- valueForKey(self, key, default=<class MiscUtils.NoDefault>)
- Get value for given key.
Suppose key is 'foo'.
This method returns the value with the following precedence:
1. Methods before non-methods
2. Public attributes before private attributes
More specifically, this method then returns one of the following:
* self.foo()
* self._foo()
* self.foo
* self._foo
... or default, if it was specified,
otherwise invokes and returns result of valueForUnknownKey().
Note that valueForUnknownKey() normally returns an exception.
See valueForName() which is a more advanced version of this method
that allows multiple, qualified keys.
- valueForKeySequence(self, listOfKeys, default=None)
- Get the value for the given list of keys.
- valueForName(self, keysString, default=None)
- Get the value for the given keysString.
This is the more advanced version of valueForKey(), which can only
handle single names. This method can handle
'foo', 'foo1.foo2', 'a.b.c.d', etc.
It will traverse dictionaries if needed.
- valueForUnknownKey(self, key, default)
- valuesForNames(self, keys, default=None, defaults=None, forgive=0, includeNames=0)
- Get all values for given names.
Returns a list of values that match the given keys, each of which is
passed through valueForName() and so could be of the form 'a.b.c'.
keys and defaults are sequences.
default is any kind of object.
forgive and includeNames are flags.
If default is not None, then it is substituted when a key is not found.
Otherwise, if defaults is not None, then its corresponding/parallel
value for the current key is substituted when a key is not found.
Otherwise, if forgive is true, then unknown keys simply don't produce
any values.
Otherwise, if default and defaults are None, and forgive is false,
then the unknown keys will probably raise an exception through
self.valueForUnknownKey() although that method can always return
a final, default value.
if keys is None, then None is returned.
If keys is an empty list, then None is returned.
Often these last four arguments are specified by key.
Examples:
names = ['origin.x', 'origin.y', 'size.width', 'size.height']
obj.valuesForNames(names)
obj.valuesForNames(names, default=0.0)
obj.valuesForNames(names, defaults=[0.0, 0.0, 100.0, 100.0])
obj.valuesForNames(names, forgive=0)
@@ 2000-03-04 ce: includeNames is only supported when forgive=1.
It should be supported for the other cases.
It should be documented.
It should be included in the test cases.
|
|