def _reportOops(self, reason, entries, exc_info=None): """Register an oops.""" if exc_info is None: exc_info = sys.exc_info() description = [ ('Reason', reason), ('Entries', str(entries)), ] errorlog.globalErrorUtility.raising( exc_info, errorlog.ScriptRequest(description))
def _replacement_branchChanged(self, user_id, branch_id, stacked_on_url, last_revision, *format_strings): """Log an oops and raise an xmlrpc fault.""" request = errorlog.ScriptRequest([('source', branch_id), ('error-explanation', "An error occurred")]) try: raise TimeoutError() except TimeoutError: f = sys.exc_info() report = errorlog.globalErrorUtility.raising(f, request) # Record the id for checking later. self.generated_oopsids.append(report['id']) raise xmlrpclib.Fault(-1, report)
def _record_oops(self, message=None): """Record an oops for the current exception. This must only be called while handling an exception. :param message: custom explanatory error message. Do not use str(exception) to fill in this parameter, it should only be set when a human readable error has been explicitly generated. """ request = errorlog.ScriptRequest([ ('branch_id', self.branch_id), ('source', self.source), ('dest', self.dest), ('error-explanation', str(message))]) request.URL = get_canonical_url_for_branch_name(self.unique_name) errorlog.globalErrorUtility.raising(sys.exc_info(), request) return request.oopsid
def unexpectedError(self, failure): request = errorlog.ScriptRequest([('branch_id', self.branch_id), ('source', self.source_url), ('dest', self.destination_url), ('error-explanation', failure.getErrorMessage())]) request.URL = get_canonical_url_for_branch_name(self.unique_name) # If the sub-process exited abnormally, the stderr it produced is # probably a much more interesting traceback than the one attached to # the Failure we've been passed. tb = None if failure.check(error.ProcessTerminated, UnexpectedStderr): tb = getattr(failure, 'error', None) if tb is None: tb = failure.getTraceback() errorlog.globalErrorUtility.raising((failure.type, failure.value, tb), request) self.logger.info('Recorded %s', request.oopsid)
def _logOopsFromFailure(self, failure): config = errorlog.globalErrorUtility._oops_config context = { 'twisted_failure': failure, 'http_request': errorlog.ScriptRequest( [('code_import_job_id', self._job_id)], self._target_url), } report = config.create(context) def log_oops_if_published(ids): if ids: self._logger.info( "Logged OOPS id %s: %s: %s", report['id'], report.get('type', 'No exception type'), report.get('value', 'No exception value')) d = config.publish(report) d.addCallback(log_oops_if_published) return d
def handle_error(failure=None, **kw): # It gets really confusing if we raise an exception from this # method (the branch remains locked, but this isn't obvious to # the client). We could just log the failure using Twisted's # log.err but this results in text containing traceback # information etc being written to stderr. Since stderr is # displayed to the user, if for example they arrive at this point # via the smart server, we want to ensure that the message is # sanitised. So what we will do is raise an oops and ask the user # to log a bug with the oops information. # See bugs 674305 and 675517 for details. request = errorlog.ScriptRequest([('source', virtual_url_fragment), ('error-explanation', failure.getErrorMessage())]) self.unexpectedError(failure, request) fault = faults.OopsOccurred("updating a Launchpad branch", request.oopsid) # Twisted's log.err used to write to stderr but it doesn't now so # we will write to stderr as well as log.err. print >> sys.stderr, repr(fault) log.err(repr(fault)) return fault