Exemplo n.º 1
0
def handle_errors(func, *args, **kwargs):
    """Catch exceptions raised by the main program function and then print
        a message and/or exit with an appropriate return code.
        """

    traceback_str = misc.get_traceback_message()

    try:
        # Out of memory errors can be raised as EnvironmentErrors with
        # an errno of ENOMEM, so in order to handle those exceptions
        # with other errnos, we nest this try block and have the outer
        # one handle the other instances.
        try:
            __ret = func(*args, **kwargs)
        except (MemoryError, EnvironmentError) as __e:
            if isinstance(__e, EnvironmentError) and \
                __e.errno != errno.ENOMEM:
                raise
            error("\n" + misc.out_of_memory())
            __ret = EXIT_OOPS
    except SystemExit as __e:
        raise __e
    except (PipeError, KeyboardInterrupt):
        # Don't display any messages here to prevent possible further
        # broken pipe (EPIPE) errors.
        __ret = EXIT_OOPS
    except:
        traceback.print_exc()
        error(traceback_str)
        __ret = 99
    return __ret
Exemplo n.º 2
0
 def __display_memory_err(self):
     try:
         dmsg = misc.out_of_memory()
         msg_stripped = dmsg.replace("\n", " ")
         gui_misc.error_occurred(None, msg_stripped, _("Package Manager"), gtk.MESSAGE_ERROR)
     except (MemoryError, EnvironmentError), e:
         if isinstance(e, EnvironmentError) and e.errno != errno.ENOMEM:
             raise
         print dmsg
Exemplo n.º 3
0
 def __display_memory_err(self):
     try:
         dmsg = misc.out_of_memory()
         msg_stripped = dmsg.replace("\n", " ")
         gui_misc.error_occurred(None, msg_stripped, _("Package Manager"),
                                 gtk.MESSAGE_ERROR)
     except (MemoryError, EnvironmentError), e:
         if isinstance(e, EnvironmentError) and \
             e.errno != errno.ENOMEM:
             raise
         print dmsg
Exemplo n.º 4
0
def handle_errors(func, *args, **kwargs):
        """Catch exceptions raised by the main program function and then print
        a message and/or exit with an appropriate return code.
        """

        traceback_str = misc.get_traceback_message()

        try:
                # Out of memory errors can be raised as EnvironmentErrors with
                # an errno of ENOMEM, so in order to handle those exceptions
                # with other errnos, we nest this try block and have the outer
                # one handle the other instances.
                try:
                        __ret = func(*args, **kwargs)
                except (MemoryError, EnvironmentError), __e:
                        if isinstance(__e, EnvironmentError) and \
                            __e.errno != errno.ENOMEM:
                                raise
                        logger.error("\n" + misc.out_of_memory())
                        __ret = EXIT_OOPS
        except SystemExit, __e:
                raise __e
Exemplo n.º 5
0
def handle_errors(func, *args, **kwargs):
    """Catch exceptions raised by the main program function and then print
        a message and/or exit with an appropriate return code.
        """

    traceback_str = misc.get_traceback_message()

    try:
        # Out of memory errors can be raised as EnvironmentErrors with
        # an errno of ENOMEM, so in order to handle those exceptions
        # with other errnos, we nest this try block and have the outer
        # one handle the other instances.
        try:
            __ret = func(*args, **kwargs)
        except (MemoryError, EnvironmentError) as __e:
            if isinstance(__e, EnvironmentError) and \
                __e.errno != errno.ENOMEM:
                raise
            error("\n" + misc.out_of_memory())
            __ret = EXIT_OOPS
    except SystemExit as __e:
        raise __e
    except (PipeError, KeyboardInterrupt):
        # Don't display any messages here to prevent possible further
        # broken pipe (EPIPE) errors.
        __ret = EXIT_OOPS
    except apx.VersionException as __e:
        error(
            _("The sysrepo command appears out of sync with the "
              "libraries provided\nby pkg:/package/pkg. The client "
              "version is {client} while the library\nAPI version is "
              "{api}.").format(client=__e.received_version,
                               api=__e.expected_version))
        __ret = EXIT_OOPS
    except:
        traceback.print_exc()
        error(traceback_str)
        __ret = 99
    return __ret
Exemplo n.º 6
0
    warnings.simplefilter('error')
    if six.PY3:
        # disable ResourceWarning: unclosed file
        warnings.filterwarnings("ignore", category=ResourceWarning)

    try:
        __ret = main_func()
    except (PipeError, KeyboardInterrupt):
        # We don't want to display any messages here to prevent
        # possible further broken pipe (EPIPE) errors.
        __ret = EXIT_OOPS
    except (pkg.actions.ActionError, trans.TransactionError, EnvironmentError,
            RuntimeError, pkg.fmri.FmriError, apx.ApiException) as _e:
        if isinstance(_e, EnvironmentError) and \
            _e.errno == errno.ENOMEM:
            error("\n" + misc.out_of_memory())
        if not (isinstance(_e, IOError) and _e.errno == errno.EPIPE):
            # Only print message if failure wasn't due to
            # broken pipe (EPIPE) error.
            print("pkgsend: {0}".format(_e), file=sys.stderr)
        __ret = EXIT_OOPS
    except MemoryError:
        error("\n" + misc.out_of_memory())
        __ret = EXIT_OOPS
    except SystemExit as _e:
        raise _e
    except:
        traceback.print_exc()
        error(misc.get_traceback_message())
        __ret = 99
    sys.exit(__ret)
Exemplo n.º 7
0
    def test_out_of_memory(self):
        """Verify that misc.out_of_memory doesn't raise an exception
                and displays the amount of memory that was in use."""

        self.assertRegexp(misc.out_of_memory(), "virtual memory was in use")
Exemplo n.º 8
0
    traceback_str = misc.get_traceback_message()

    try:
        # Out of memory errors can be raised as EnvironmentErrors with
        # an errno of ENOMEM, so in order to handle those exceptions
        # with other errnos, we nest this try block and have the outer
        # one handle the other instances.
        try:
            __ret = main_func()
        except (MemoryError, EnvironmentError), __e:
            if isinstance(__e, EnvironmentError) and __e.errno != errno.ENOMEM:
                raise
            if __img:
                __img.history.abort(RESULT_FAILED_OUTOFMEMORY)
            error("\n" + misc.out_of_memory())
            __ret = 1
    except SystemExit, __e:
        raise
    except (PipeError, KeyboardInterrupt):
        if __img:
            __img.history.abort(RESULT_CANCELED)
        # We don't want to display any messages here to prevent
        # possible further broken pipe (EPIPE) errors.
        __ret = 1
    except:
        traceback.print_exc()
        error(traceback_str)
        __ret = 99
    sys.exit(__ret)
Exemplo n.º 9
0
        def test_out_of_memory(self):
                """Verify that misc.out_of_memory doesn't raise an exception
                and displays the amount of memory that was in use."""

                self.assertRegexp(misc.out_of_memory(),
                    "virtual memory was in use")