示例#1
0
文件: replay.py 项目: zaheerm/feat
    def _check_snapshot(self, old_agent, old_protocols):
        # check that the state so far matches the snapshop
        # if old_agent is None, it means that the snapshot is first entry
        # we are replaynig - hence we have no state to compare to
        if old_agent is not None:
            try:
                if self.agent != old_agent:
                    comp = deep_compare(self.agent._get_state(), old_agent._get_state())
                    info = "  INFO:        %s: %s\n" % comp if comp else ""

                    raise ReplayError(
                        "States of current agent mismatch the "
                        "old agent\nInfo: %s\nOld: %s\n"
                        "Loaded: %s." % (info, pformat(old_agent._get_state()), pformat(self.agent._get_state()))
                    )
                if len(self.protocols) != len(old_protocols):
                    raise ReplayError(
                        "The number of protocols mismatch. " "\nOld: %r\nLoaded: %r" % (old_protocols, self.protocols)
                    )
                else:
                    for protocol in self.protocols:
                        if protocol not in old_protocols:
                            raise ReplayError(
                                "One of the protocols was not "
                                "found.\nOld: %s\nLoaded: %s" % (pformat(old_protocols), pformat(self.protocols))
                            )
            except RuntimeError, e:
                exc_info = sys.exc_info()
                raise ReplayError(
                    "Runtime error during replay of %s: %s" % (self.agent.type_name, error.get_exception_message(e))
                ), None, exc_info[2]
示例#2
0
文件: options.py 项目: f3at/feat
def _load_module(option, opt, value, parser):
    try:
        reflect.named_module(value)
    except ImportError, e:
        from feat.common import error
        raise OptionError("Cannot import module %s: %s" % (
            value, error.get_exception_message(e))), None, sys.exc_info()[2]
示例#3
0
文件: httpserver.py 项目: f3at/feat
    def initiate(self):
        self.debug('Initiating %s', self.log_ident)
        assert not self.initiated, "Already initiated"
        self.initiated = True

        try:
            self.onInitiate()
        except HTTPError, e:
            self.warning("Error during initiation: %s",
                         error.get_exception_message(e))
            self._make_error(e.status_code, e.status_message)
示例#4
0
文件: httpserver.py 项目: f3at/feat
 def allContentReceived(self):
     self.debug('All content received on %s', self.log_ident)
     assert not self.received, "Already been notified"
     if self.finished:
         return
     self.received = True
     try:
         self.onAllContentReceived()
     except HTTPError, e:
         self.warning("Error during finalization: %s",
                      error.get_exception_message(e))
         self._make_error(e.status_code, e.status_message)
         return
示例#5
0
文件: httpserver.py 项目: f3at/feat
    def dataReceived(self, data):
        self.received_bytes += len(data)

        if self.finished:
            return

        try:
            self.onDataReceived(data)
        except HTTPError, e:
            self.warning("Error during data processing: %s",
                         error.get_exception_message(e))
            self._make_error(e.status_code, e.status_message)
            return
示例#6
0
文件: agency.py 项目: f3at/feat
    def link_log_file(self, filename):
        if not self.config.agency.daemonize:
            # if haven't demonized the log is just at the users console
            return

        logfile, _ = log.FluLogKeeper.get_filenames()
        linkname = os.path.join(self.config.agency.logdir, filename)
        try:
            os.unlink(linkname)
        except OSError:
            pass
        try:
            os.symlink(logfile, linkname)
        except OSError as e:
            self.warning("Failed to link log file %s to %s: %s", logfile, linkname, error.get_exception_message(e))
示例#7
0
文件: agency.py 项目: sylane/feat
    def _link_log_file(self, filename):
        if not self.config['agency']['daemonize']:
            return

        logfile, _ = log.FluLogKeeper.get_filenames()
        basedir = os.path.dirname(logfile)
        linkname = os.path.join(basedir, filename)
        try:
            os.unlink(linkname)
        except OSError:
            pass
        try:
            os.symlink(logfile, linkname)
        except OSError as e:
            self.warning("Failed to link log file %s to %s: %s",
                         logfile, linkname, error.get_exception_message(e))
示例#8
0
文件: httpserver.py 项目: f3at/feat
    def activate(self):
        self.debug('Activating %s', self.log_ident)
        assert not self.activated, "request already active"
        self.activated = True

        self._activate_transport()

        if self.finished:
            # The request was finished before being activated
            time.call_later(0, self._cleanup)
            return

        try:
            self.onActivate()
        except HTTPError, e:
            self.warning("Error during activation: %s",
                         error.get_exception_message(e))
            self._make_error(e.status_code, e.status_message)
示例#9
0
文件: resources.py 项目: sylane/feat
    def from_exception(cls, ex):
        if isinstance(ex, http.HTTPError):
            code = ex.status_code
        elif isinstance(ex, error.FeatError):
            code = ex.eror_code
        else:
            code = None

        if isinstance(ex, error.FeatError):
            message = ex.error_name
        else:
            message = str(ex)

        if not message:
            message = type(ex).__name__

        debug = error.get_exception_message(ex)
        trace = error.get_exception_traceback(ex)

        return cls(code=code, message=message, debug=debug, trace=trace)
示例#10
0
文件: resources.py 项目: zaheerm/feat
    def from_exception(cls, ex):
        error_type = ErrorTypes.generic
        status_code = None
        error_code = None
        message = None
        subjects = None
        reasons = None
        debug = None
        trace = None

        if isinstance(ex, error.FeatError):
            error_code = ex.error_code
            message = ex.error_name

        if isinstance(ex, http.HTTPError):
            error_type = ErrorTypes.http
            status_code = ex.status_code
            if error_code is None:
                error_code = int(status_code)

        if isinstance(ex, ParameterError):
            error_type = ex.error_type
            status_code = http.Status.BAD_REQUEST
            subjects = ex.parameters
            if isinstance(ex, InvalidParameters):
                reasons = ex.reasons

        if not message:
            message = str(ex) or type(ex).__name__

        if not isinstance(ex, http.HTTPError):
            debug = error.get_exception_message(ex)
            trace = error.get_exception_traceback(ex)

        return cls(error_type=error_type, error_code=error_code,
                   status_code=status_code, message=message,
                   subjects=subjects, reasons=reasons,
                   debug=debug, trace=trace)
示例#11
0
文件: httpserver.py 项目: f3at/feat
        self._activate_transport()

        if self.finished:
            # The request was finished before being activated
            time.call_later(0, self._cleanup)
            return

        try:
            self.onActivate()
        except HTTPError, e:
            self.warning("Error during activation: %s",
                         error.get_exception_message(e))
            self._make_error(e.status_code, e.status_message)
        except Exception, e:
            self.warning("Error during activation: %s",
                         error.get_exception_message(e))
            self._make_error(http.Status.INTERNAL_SERVER_ERROR)
            raise

    def dataReceived(self, data):
        self.received_bytes += len(data)

        if self.finished:
            return

        try:
            self.onDataReceived(data)
        except HTTPError, e:
            self.warning("Error during data processing: %s",
                         error.get_exception_message(e))
            self._make_error(e.status_code, e.status_message)