Пример #1
0
def handle_gui_exception(e, msg, parent, formatMsg=True, logMsg=None):
    """
    Handles an exception for the gui by logging the stack trace and
    displaying a user-friendly internationalized message.

    msg = User friendly message to display in GUI.
    parent = Parent window where the error originates.
    logMsg = Optional message to be logged in addition to stack trace.
    formatMsg = if true, string sub the exception error in the msg
    """

    if logMsg:
        log.error(logMsg)
    log.exception(e)

    # If exception is of these types we ignore the given display msg:
    if isinstance(e, socket_error):
        errorWindow(_('Network error, unable to connect to server. Please see /var/log/rhsm/rhsm.log for more information.'),
                parent=parent)
    elif isinstance(e, SSL.SSLError):
        errorWindow(_('Unable to verify server\'s identity: %s') % str(e),
                parent=parent)
    elif isinstance(e, connection.NetworkException):
        # NOTE: yes this looks a lot like the socket error, but I think these
        # were actually intended to display slightly different messages:
        errorWindow(_("Network error. Please check the connection details, or see /var/log/rhsm/rhsm.log for more information."), parent=parent)
    elif isinstance(e, connection.RemoteServerException):
        # This is what happens when there's an issue with the server on the other side of the wire
        errorWindow(_("Remote server error. Please check the connection details, or see /var/log/rhsm/rhsm.log for more information."), parent=parent)
    elif isinstance(e, connection.RestlibException):
        # If this exception's code is in the 200 range (such as 202 ACCEPTED)
        # we're going to ignore the message we were given and just display
        # the message from the server as an info dialog. (not an error)
        if 200 < int(e.code) < 300:
            message = linkify(e.msg)
            messageWindow.InfoDialog(messageWindow.wrap_text(message))

        else:
            try:
                if formatMsg:
                    message = msg % linkify(e.msg)
                else:
                    message = linkify(e.msg)
            except:
                message = msg

            errorWindow(message, parent=parent)

    elif isinstance(e, connection.BadCertificateException):
        errorWindow(_("Bad CA certificate: %s") % e.cert_path, parent=parent)
    else:
        #catch-all, try to interpolate and if it doesn't work out, just display the message
        try:
            interpolatedStr = msg % e
            errorWindow(interpolatedStr, parent=parent)
        except:
            errorWindow(msg, parent=parent)
Пример #2
0
def handle_gui_exception(e, msg, parent, format_msg=True, log_msg=None):
    """
    Handles an exception for the gui by logging the stack trace and
    displaying a user-friendly internationalized message.

    e = either an exception or a tuple returned from sys.exc_info()
    msg = User friendly message to display in GUI.
    parent = Parent window where the error originates.
    log_msg = Optional message to be logged in addition to stack trace.
    format_msg = if true, string sub the exception error in the msg
    """
    if isinstance(e, tuple):
        if not log_msg:
            log_msg = str(e[1])

        log.error(log_msg, exc_info=e)
        # Get the class instance of the exception
        e = e[1]
    else:
        if log_msg:
            log.error(log_msg)
        log.exception(e)

    exception_mapper = ExceptionMapper()
    mapped_message = exception_mapper.get_message(e)
    if mapped_message:
        if isinstance(e, connection.RestlibException):
            # If this exception's code is in the 200 range (such as 202 ACCEPTED)
            # we're going to ignore the message we were given and just display
            # the message from the server as an info dialog. (not an error)
            if 200 < int(e.code) < 300:
                message = linkify(mapped_message)
                messageWindow.InfoDialog(messageWindow.wrap_text(message))

            else:
                try:
                    if format_msg:
                        message = msg % linkify(mapped_message)
                    else:
                        message = linkify(mapped_message)
                except Exception:
                    message = msg

                show_error_window(message, parent=parent)
        else:
            show_error_window(mapped_message, parent)
    else:
        #catch-all, try to interpolate and if it doesn't work out, just display the message
        try:
            interpolated_str = msg % e
            show_error_window(interpolated_str, parent=parent)
        except Exception:
            show_error_window(msg, parent=parent)
Пример #3
0
def handle_gui_exception(e, msg, parent, format_msg=True, log_msg=None):
    """
    Handles an exception for the gui by logging the stack trace and
    displaying a user-friendly internationalized message.

    e = either an exception or a tuple returned from sys.exc_info()
    msg = User friendly message to display in GUI.
    parent = Parent window where the error originates.
    log_msg = Optional message to be logged in addition to stack trace.
    format_msg = if true, string sub the exception error in the msg
    """
    if isinstance(e, tuple):
        if not log_msg:
            log_msg = str(e[1])

        log.error(log_msg, exc_info=e)
        # Get the class instance of the exception
        e = e[1]
    else:
        if log_msg:
            log.error(log_msg)
        log.exception(e)

    exception_mapper = ExceptionMapper()
    mapped_message = exception_mapper.get_message(e)
    if mapped_message:
        if isinstance(e, connection.RestlibException):
            # If this exception's code is in the 200 range (such as 202 ACCEPTED)
            # we're going to ignore the message we were given and just display
            # the message from the server as an info dialog. (not an error)
            if 200 < int(e.code) < 300:
                message = linkify(mapped_message)
                messageWindow.InfoDialog(messageWindow.wrap_text(message))

            else:
                try:
                    if format_msg:
                        message = msg % linkify(mapped_message)
                    else:
                        message = linkify(mapped_message)
                except Exception:
                    message = msg

                show_error_window(message, parent=parent)
        else:
            show_error_window(mapped_message, parent)
    else:
        #catch-all, try to interpolate and if it doesn't work out, just display the message
        try:
            interpolated_str = msg % e
            show_error_window(interpolated_str, parent=parent)
        except Exception:
            show_error_window(msg, parent=parent)
Пример #4
0
 def date_entry_validate(self):
     """
     validate the date and pop up a box if not valid
     """
     try:
         self._date_validate(self._date_entry.get_text())
         self.emit('date-picked-text')
         return True
     except ValueError:
         today = datetime.date.today()
         messageWindow.ErrorDialog(messageWindow.wrap_text(
                             "%s %s" % (_("Invalid date format. Please re-enter a valid date. Example: "), today.isoformat())))
         return False
Пример #5
0
 def date_entry_validate(self):
     """
     validate the date and pop up a box if not valid
     """
     try:
         self._date_validate(self._date_entry.get_text())
         self.emit('date-picked-text')
         return True
     except ValueError:
         today = datetime.date.today()
         messageWindow.ErrorDialog(messageWindow.wrap_text(
                             "%s %s" % (_("Invalid date format. Please re-enter a valid date. Example: "), today.isoformat())))
         return False
Пример #6
0
def show_error_window(message, parent=None):
    messageWindow.ErrorDialog(messageWindow.wrap_text(message), parent)
Пример #7
0
def show_info_window(message, parent=None):
    messageWindow.InfoDialog(messageWindow.wrap_text(message),
                             parent)
Пример #8
0
def show_error_window(message, parent=None):
    messageWindow.ErrorDialog(messageWindow.wrap_text(message),
                              parent)
Пример #9
0
def show_info_window(message, parent=None):
    messageWindow.InfoDialog(messageWindow.wrap_text(message), parent)