Exemple #1
0
 def handle_loop_error(err: Failure, loop_handler: LoopHandler) -> None:
     """Handle errors in a looping function and restart the loop."""
     send_problem_report(err)
     err.printTraceback()
     # Sleep to avoid tight infinite loops spamming emails
     time.sleep(3)
     # Restart the given method
     loop_handler.start_loop()
Exemple #2
0
 def handle(self, message, address):
     try:
         (v, ) = message.arguments
         self.dispatch(self._transform(float(v)))
     except Exception, e:
         f = Failure(e)
         f.printTraceback()
         log.msg('[FloatDispatcher.handle] error', e)
Exemple #3
0
 def dispatch(self, *a, **k):
     for handler in self._listeners:
         try:
             handler(*a, **k)
         except Exception, e:
             f = Failure(e)
             f.printTraceback()
             log.err(e)
Exemple #4
0
 def __init__(self, *args, **kwargs):
     try:
         raise RuntimeError()
     except RuntimeError:
         from twisted.python.failure import Failure
         f = Failure()
         f.printTraceback()
     return super(ReportingProtocolWrapper, self).__init__(*args, **kwargs)
Exemple #5
0
 def dispatch(self, *a, **k):
     for handler in self._listeners:
         try:
             handler(*a, **k)
         except Exception, e:
             f = Failure(e)
             f.printTraceback()
             log.err(e)
Exemple #6
0
 def handle(self, message, address):
     try:
         (v,) = message.arguments
         self.dispatch(self._transform(float(v)))
     except Exception, e:
         f = Failure(e)
         f.printTraceback()
         log.msg('[FloatDispatcher.handle] error', e)
Exemple #7
0
        def fail(failure: Failure) -> None:
            # If the Deferred was cancelled (e.g. during shutdown) do not try to
            # reconnect (this will cause an infinite loop of errors).
            if failure.check(CancelledError) and self._stopping:
                return

            # For a different error, print the traceback and re-connect.
            failure.printTraceback(file=sys.__stderr__)
            self._connection_waiter = None
            self._connect()
Exemple #8
0
 def write(self, data):
     """write data to some file like object only writes happen if debug was
        specified during instantiation.
     """
     if hasattr(self.fd, 'write') and hasattr(self.fd.write, '__call__') \
             and self.debug: #only write on debug true
         try:
             self.fd.write(str(data)+'\n')
         except:
             failure = Failure()
             if self.verbose: failure.printDetailedTraceback(sys.stderr)
             else: failure.printTraceback(sys.stderr)
Exemple #9
0
 def write(self, data):
     """write data to some file like object only writes happen if debug was
        specified during instantiation.
     """
     if hasattr(self.fd, 'write') and hasattr(self.fd.write, '__call__') \
             and self.debug: #only write on debug true
         try:
             self.fd.write(str(data) + '\n')
         except:
             failure = Failure()
             if self.verbose: failure.printDetailedTraceback(sys.stderr)
             else: failure.printTraceback(sys.stderr)
Exemple #10
0
 def callRemote(self, name, *args, **kw):
     """Call a specially-designated local method.
     self.callRemote('x') will first try to invoke a method named
     sync_x and return its result (which should probably be a
     Deferred).  Second, it will look for a method called async_x,
     which will be called and then have its result (or Failure)
     automatically wrapped in a Deferred.
     """
     if hasattr(self, 'sync_'+name):
         return getattr(self, 'sync_'+name)(*args, **kw)
     try:
         method = getattr(self, "async_" + name)
         return defer.succeed(method(*args, **kw))
     except:
         f = Failure()
         if self.reportAllTracebacks:
             f.printTraceback()
         return defer.fail(f)
Exemple #11
0
    def display_result(self, result):
        """display the result in debug mode, always display tracebacks
           on failure. this is callback safe. 

           @param result (object)
           @return (param -> result)
        """
        if isinstance(result, Failure):
            if hasattr(result.value, "__class__"):
                eName = result.value.__class__.__name__
            else:  # guess in event failure doesn't make sense
                try:  # preload and reset later
                    eName = sys.exc_info()[0].__name__
                except AttributeError:
                    eName = "Unknown"  # fail
                except:
                    failure = Failure()
                    self.write("Something bad has happened")
                    fd = self.fd
                    if not fd:
                        self.fd = sys.stderr
                    if self.verbose:
                        failure.printDetailedTraceback(self.fd)
                    else:
                        failure.printTraceback(self.fd)
                    # restore the previous fd object
                    self.fd = fd
                    return result
            self.write(">>> %s call raised %s" % (self.function.func_name, eName))
            # make sure the fd is valid for tracebacks
            fd = self.fd
            if not fd:
                self.fd = sys.stderr
            if self.verbose:
                result.printDetailedTraceback(self.fd)
            else:
                result.printTraceback(self.fd)
            # restore the previous fd object
            self.fd = fd
            self.write(">>>")
        else:
            self.write(">>> Returning %s -> %s" % (self.function.func_name, str(result)))
        return result
Exemple #12
0
    def callRemote(self, name, *args, **kw):
        """Call a specially-designated local method.

        self.callRemote('x') will first try to invoke a method named
        sync_x and return its result (which should probably be a
        Deferred).  Second, it will look for a method called async_x,
        which will be called and then have its result (or Failure)
        automatically wrapped in a Deferred.
        """
        if hasattr(self, 'sync_' + name):
            return getattr(self, 'sync_' + name)(*args, **kw)
        try:
            method = getattr(self, "async_" + name)
            return defer.succeed(method(*args, **kw))
        except:
            f = Failure()
            if self.reportAllTracebacks:
                f.printTraceback()
            return defer.fail(f)
Exemple #13
0
    def display_result(self, result):
        """display the result in debug mode, always display tracebacks
           on failure. this is callback safe. 

           @param result (object)
           @return (param -> result)
        """
        if isinstance(result, Failure):
            if hasattr(result.value, '__class__'):
                eName = result.value.__class__.__name__
            else:  #guess in event failure doesn't make sense
                try:  #preload and reset later
                    eName = sys.exc_info()[0].__name__
                except AttributeError:
                    eName = 'Unknown'  #fail
                except:
                    failure = Failure()
                    self.write('Something bad has happened')
                    fd = self.fd
                    if not fd: self.fd = sys.stderr
                    if self.verbose: failure.printDetailedTraceback(self.fd)
                    else: failure.printTraceback(self.fd)
                    #restore the previous fd object
                    self.fd = fd
                    return result
            self.write(">>> %s call raised %s" % \
                    (self.function.func_name, eName))
            #make sure the fd is valid for tracebacks
            fd = self.fd
            if not fd: self.fd = sys.stderr
            if self.verbose: result.printDetailedTraceback(self.fd)
            else: result.printTraceback(self.fd)
            #restore the previous fd object
            self.fd = fd
            self.write(">>>")
        else:
            self.write(">>> Returning %s -> %s" % \
                    (self.function.func_name,str(result)))
        return result
    def run(self):
        """
        Function that does common PUT/COPY/MOVE behavior.

        @return: a Deferred with a status response result.
        """

        try:
            reservation = None
            
            # Handle all validation operations here.
            yield self.fullValidation()

            # Reservation and UID conflict checking is next.
            if self.destinationadbk:    
                # Reserve UID
                self.destination_index = self.destinationparent.index()
                reservation = StoreAddressObjectResource.UIDReservation(
                    self.destination_index, self.uid, self.destination_uri
                )
                if self.indexdestination:
                    yield reservation.reserve()
            
                # UID conflict check - note we do this after reserving the UID to avoid a race condition where two requests
                # try to write the same vcard data to two different resource URIs.
                result, message, rname = self.noUIDConflict(self.uid)
                if not result:
                    log.err(message)
                    raise HTTPError(ErrorResponse(responsecode.FORBIDDEN,
                        NoUIDConflict(davxml.HRef.fromString(joinURL(parentForURL(self.destination_uri), rname.encode("utf-8"))))
                    ))
            
            # Get current quota state.
            yield self.checkQuota()

            # Do the actual put or copy
            response = (yield self.doStore())
            
            # Remember the resource's content-type.
            if self.destinationadbk:
                content_type = self.request.headers.getHeader("content-type")
                if content_type is None:
                    content_type = MimeType("text", "vcard",
                                            params={"charset":"utf-8"})
                self.destination.writeDeadProperty(
                    davxml.GETContentType.fromString(generateContentType(content_type))
                )

            # Delete the original source if needed.
            if self.deletesource:
                yield self.doSourceQuotaCheck()

            # Do quota check on destination
            if self.destquota is not None:
                yield self.doDestinationQuotaCheck()
    
            if reservation:
                yield reservation.unreserve()
    
            returnValue(response)
    
        except Exception, err:
            # Preserve the real traceback to display later, since the error-
            # handling here yields out of the generator and thereby shreds the
            # stack.
            f = Failure()

            if reservation:
                yield reservation.unreserve()
    
            # FIXME: transaction needs to be rolled back.

            # Display the traceback.  Unfortunately this will usually be
            # duplicated by the higher-level exception handler that captures
            # the thing that raises here, but it's better than losing the
            # information.
            f.printTraceback()

            raise err