def _doHandleException(self, func_name, exc_info):
        exc_val = exc_info[1]
        is_server_exception = isinstance(exc_val, ServerException)
        if is_server_exception:
            # When a component raised an explicit COM exception, it is
            # considered 'normal' - however, we still write a debug log
            # record to help track these otherwise silent exceptions.

            if sys.version_info < (2,4):
                # Note that Python 2.3 does not allow an explicit exc_info tuple
                # and passing 'True' will not work as there is no exception pending.
                # Trick things!
                if logger.isEnabledFor(logging.DEBUG):
                    try:
                        raise exc_info[0], exc_info[1], exc_info[2]
                    except:
                        logger.debug("'%s' raised COM Exception %s",
                                 func_name, exc_val, exc_info = 1)
            else:
                logger.debug("'%s' raised COM Exception %s",
                             func_name, exc_val, exc_info=exc_info)

            return exc_val.errno
        # Unhandled exception - always print a warning and the traceback.
        # As above, trick the logging module to handle Python 2.3
        if sys.version_info < (2,4):
            try:
                raise exc_info[0], exc_info[1], exc_info[2]
            except:
                logger.exception("Unhandled exception calling '%s'", func_name)
        else:
            logger.error("Unhandled exception calling '%s'", func_name,
                         exc_info=exc_info)
        return nsError.NS_ERROR_FAILURE
Exemple #2
0
    def autoRegisterComponents(self, when, directory):
        directory_path = directory.path
        self.num_modules_this_register = 0
        logger.debug("Auto-registering all Python components in '%s'",
                     directory_path)

        # ToDo - work out the right thing here
        # eg - do we recurse?
        # - do we support packages?
        entries = directory.directoryEntries
        while entries.HasMoreElements():
            entry = entries.GetNext(components.interfaces.nsIFile)
            if os.path.splitext(entry.path)[1] == ".py":
                try:
                    self.autoRegisterComponent(when, entry)
                # Handle some common user errors
                except xpcom.COMException, details:
                    from xpcom import nsError
                    # If the interface name does not exist, suppress the traceback
                    if details.errno == nsError.NS_ERROR_NO_INTERFACE:
                        logger.error("Registration of '%s' failed\n %s",
                                     entry.leafName, details.message)
                    else:
                        logger.exception("Registration of '%s' failed!",
                                         entry.leafName)
                except SyntaxError, details:
                    # Syntax error in source file - no useful traceback here either.
                    logger.error("Registration of '%s' failed\n %s",
                                 entry.leafName, details)
                except:
    def autoRegisterComponents (self, when, directory):
        directory_path = directory.path
        self.num_modules_this_register = 0
        logger.debug("Auto-registering all Python components in '%s'", directory_path)

        # ToDo - work out the right thing here
        # eg - do we recurse?
        # - do we support packages?
        entries = directory.directoryEntries
        while entries.HasMoreElements():
            entry = entries.GetNext(components.interfaces.nsIFile)
            if os.path.splitext(entry.path)[1]==".py":
                try:
                    self.autoRegisterComponent(when, entry)
                # Handle some common user errors
                except xpcom.COMException as details:
                    from xpcom import nsError
                    # If the interface name does not exist, suppress the traceback
                    if details.errno==nsError.NS_ERROR_NO_INTERFACE:
                        logger.error("Registration of '%s' failed\n %s",
                                     entry.leafName, details.message)
                    else:
                        logger.exception("Registration of '%s' failed!", entry.leafName)
                except SyntaxError as details:
                    # Syntax error in source file - no useful traceback here either.
                    logger.error("Registration of '%s' failed\n %s",
                                 entry.leafName, details)
                except:
                    # All other exceptions get the full traceback.
                    logger.exception("Registration of '%s' failed.", entry.leafName)
Exemple #4
0
    def createInstance(self, outer, iid):
        if outer is not None:
            raise xpcom.ServerException(nsError.NS_ERROR_NO_AGGREGATION)

        logger.debug("Python Factory creating %s", self.klass.__name__)
        try:
            return self.klass()
        except:
            # An exception here may not be obvious to the user - none
            # of their code has been called yet.  It can be handy on
            # failure to tell the user what class failed!
            logger.error("Creation of class '%r' failed!\nException details follow\n",
                           self.klass)
            # The framework itself will also report the error.
            raise
Exemple #5
0
    def createInstance(self, outer, iid):
        if outer is not None:
            raise xpcom.ServerException(nsError.NS_ERROR_NO_AGGREGATION)

        logger.debug("Python Factory creating %s", self.klass.__name__)
        try:
            return self.klass()
        except:
            # An exception here may not be obvious to the user - none
            # of their code has been called yet.  It can be handy on
            # failure to tell the user what class failed!
            logger.error(
                "Creation of class '%r' failed!\nException details follow\n",
                self.klass)
            # The framework itself will also report the error.
            raise
Exemple #6
0
    def _doHandleException(self, func_name, exc_info):
        exc_val = exc_info[1]
        is_server_exception = isinstance(exc_val, ServerException)
        if is_server_exception:
            # When a component raised an explicit COM exception, it is
            # considered 'normal' - however, we still write a debug log
            # record to help track these otherwise silent exceptions.

            logger.debug("'%s' raised COM Exception %s",
                         func_name, exc_val, exc_info=exc_info)

            return exc_val.errno
        # Unhandled exception - always print a warning and the traceback.
        # As above, trick the logging module to handle Python 2.3
        logger.error("Unhandled exception calling '%s'", func_name,
                     exc_info=exc_info)
        return nsError.NS_ERROR_FAILURE
Exemple #7
0
    def _doHandleException(self, func_name, exc_info):
        exc_val = exc_info[1]
        is_server_exception = isinstance(exc_val, ServerException)
        if is_server_exception:
            # When a component raised an explicit COM exception, it is
            # considered 'normal' - however, we still write a debug log
            # record to help track these otherwise silent exceptions.

            if sys.version_info < (2, 4):
                # Note that Python 2.3 does not allow an explicit exc_info tuple
                # and passing 'True' will not work as there is no exception pending.
                # Trick things!
                if logger.isEnabledFor(logging.DEBUG):
                    try:
                        raise exc_info[0], exc_info[1], exc_info[2]
                    except:
                        logger.debug("'%s' raised COM Exception %s",
                                     func_name,
                                     exc_val,
                                     exc_info=1)
            else:
                logger.debug("'%s' raised COM Exception %s",
                             func_name,
                             exc_val,
                             exc_info=exc_info)

            return exc_val.errno
        # Unhandled exception - always print a warning and the traceback.
        # As above, trick the logging module to handle Python 2.3
        if sys.version_info < (2, 4):
            try:
                raise exc_info[0], exc_info[1], exc_info[2]
            except:
                logger.exception("Unhandled exception calling '%s'", func_name)
        else:
            logger.error("Unhandled exception calling '%s'",
                         func_name,
                         exc_info=exc_info)
        return nsError.NS_ERROR_FAILURE
Exemple #8
0
                        # cannot unwrap
                        exc = xpcom.server.UnwrapObject(exc)
                        exc.inner = exc_val
                        exc_val = exc
                    except ValueError, e:
                        pyexec = exc_val
                        exc_val = COMException(exc.result, exc.message)
                        exc_val.filename = exc.filename
                        exc_val.lineNumber = exc.lineNumber
                        exc_val.filename = exc.filename
                        exc_val.name = exc.name
                        exc_val.location = exc.location
                        exc_val.inner = pyexec
        else:
            # Unhandled exception - always print a warning.
            logger.error("Unhandled exception calling '%s'", func_name, exc_info=exc_info)
            if hasattr(exc_val, "__class__"):
                message = "%s: %s" % (exc_info[1].__class__.__name__, str(exc_val))
            else:
                message = str(exc_val)
            exc_val = COMException(nsError.NS_ERROR_FAILURE, message)
            if components:
                exc_val.setExcInfo(exc_info)

        if components:
            xs.currentExceptionManager.setCurrentException(exc_val)

        return exc_val.result

    # Called whenever an unhandled Python exception is detected as a result
    # of _CallMethod_ - this exception may have been raised during the _CallMethod_