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
def __display_unknown_err(self, trace): dmsg = _("An unknown error occurred") md = gtk.MessageDialog(type=gtk.MESSAGE_ERROR, message_format=dmsg) close_btn = md.add_button(gtk.STOCK_CLOSE, 100) md.set_default_response(100) dmsg = misc.get_traceback_message() # We remove all \n except the initial one. dmsg = "\n" + dmsg.replace("\n", " ").lstrip() md.format_secondary_text(dmsg) md.set_title(_('Unexpected Error')) textview = gtk.TextView() textview.show() textview.set_editable(False) textview.set_wrap_mode(gtk.WRAP_WORD) sw = gtk.ScrolledWindow() sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) sw.add(textview) fr = gtk.Frame() fr.set_shadow_type(gtk.SHADOW_IN) fr.add(sw) ca = md.get_content_area() ca.pack_start(fr) textbuffer = textview.get_buffer() textbuffer.create_tag("bold", weight=pango.WEIGHT_BOLD) textbuffer.create_tag("level1", left_margin=30, right_margin=10) textiter = textbuffer.get_end_iter() textbuffer.insert_with_tags_by_name(textiter, _("Error details:\n"), "bold") textbuffer.insert_with_tags_by_name(textiter, trace.getvalue(), "level1") publisher_str = "" if self.parent: publisher_str = \ gui_misc.get_publishers_for_output( self.parent.get_api_object()) if publisher_str != "": textbuffer.insert_with_tags_by_name( textiter, _("\nList of configured publishers:"), "bold") textbuffer.insert_with_tags_by_name(textiter, publisher_str + "\n", "level1") if publisher_str == "": textbuffer.insert_with_tags_by_name( textiter, _("\nPlease include output from:\n"), "bold") textbuffer.insert(textiter, "$ pkg publisher\n") md.set_size_request(550, 400) md.set_resizable(True) close_btn.grab_focus() md.show_all() md.run() md.destroy()
def __display_unknown_err(self, trace): dmsg = _("An unknown error occurred") md = gtk.MessageDialog(type=gtk.MESSAGE_ERROR, message_format=dmsg) close_btn = md.add_button(gtk.STOCK_CLOSE, 100) md.set_default_response(100) dmsg = misc.get_traceback_message() # We remove all \n except the initial one. dmsg = "\n" + dmsg.replace("\n", " ").lstrip() md.format_secondary_text(dmsg) md.set_title(_("Unexpected Error")) textview = gtk.TextView() textview.show() textview.set_editable(False) textview.set_wrap_mode(gtk.WRAP_WORD) sw = gtk.ScrolledWindow() sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) sw.add(textview) fr = gtk.Frame() fr.set_shadow_type(gtk.SHADOW_IN) fr.add(sw) ca = md.get_content_area() ca.pack_start(fr) textbuffer = textview.get_buffer() textbuffer.create_tag("bold", weight=pango.WEIGHT_BOLD) textbuffer.create_tag("level1", left_margin=30, right_margin=10) textiter = textbuffer.get_end_iter() textbuffer.insert_with_tags_by_name(textiter, _("Error details:\n"), "bold") textbuffer.insert_with_tags_by_name(textiter, trace.getvalue(), "level1") publisher_str = "" if self.parent: publisher_str = gui_misc.get_publishers_for_output(self.parent.get_api_object()) if publisher_str != "": textbuffer.insert_with_tags_by_name(textiter, _("\nList of configured publishers:"), "bold") textbuffer.insert_with_tags_by_name(textiter, publisher_str + "\n", "level1") if publisher_str == "": textbuffer.insert_with_tags_by_name(textiter, _("\nPlease include output from:\n"), "bold") textbuffer.insert(textiter, "$ pkg publisher\n") md.set_size_request(550, 400) md.set_resizable(True) close_btn.grab_focus() md.show_all() md.run() md.destroy()
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
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
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) # Vim hints # vim:ts=8:sw=8:et:fdm=marker
if __name__ == "__main__": misc.setlocale(locale.LC_ALL, "", error) gettext.install("pkg", "/usr/share/locale", codeset=locale.getpreferredencoding()) misc.set_fd_limits(printer=error) # Make all warnings be errors. import warnings warnings.simplefilter('error') try: __ret = main_func() except (pkg.actions.ActionError, trans.TransactionError, RuntimeError, pkg.fmri.FmriError, apx.ApiException) as __e: print("pkgmerge: {0}".format(__e), file=sys.stderr) __ret = EXIT_OOPS except (PipeError, KeyboardInterrupt): __ret = EXIT_OOPS except SystemExit as __e: raise __e except Exception as __e: traceback.print_exc() error(misc.get_traceback_message(), exitcode=None) __ret = 99 finally: cleanup() sys.exit(__ret)
for f in fm.walk(): # A non-readonly FileManager will move a file under a # non-preferred layout to the preferred layout during a # lookup. fm.lookup(f) except file_manager.UnrecognizedFilePaths as e: emsg(e) return 1 return 0 if __name__ == "__main__": setlocale(locale.LC_ALL, "") gettext.install("pkg", "/usr/share/locale") 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) as __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())
# should be printed; later actions are all # emitted and should only be printed if not # duplicates. if i == 0: print >> outfile, s elif s not in emitted: print >> outfile, s emitted.add(s) except IOError, e: error(_("Cannot write output %s") % e) return 0 if __name__ == "__main__": # Make all warnings be errors. warnings.simplefilter('error') try: exit_code = main_func() except (PipeError, KeyboardInterrupt): exit_code = 1 except SystemExit, __e: exit_code = __e except Exception, __e: traceback.print_exc() error(misc.get_traceback_message(), exitcode=None) exit_code = 99 sys.exit(exit_code)
for f in fm.walk(): # A non-readonly FileManager will move a file under a # non-preferred layout to the preferred layout during a # lookup. fm.lookup(f) except file_manager.UnrecognizedFilePaths, e: emsg(e) return 1 return 0 if __name__ == "__main__": setlocale(locale.LC_ALL, "") gettext.install("pkg", "/usr/share/locale") 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
"lint.manifest003") else: manifests.append(None) return manifests def _make_list(opt): """Makes a list out of opt, and returns it.""" if isinstance(opt, list): return opt elif opt is None: return [] else: return [opt] if __name__ == "__main__": try: value = main_func() sys.exit(value) except (PipeError, KeyboardInterrupt): # We don't want to display any messages here to prevent # possible further broken pipe (EPIPE) errors. __ret = 1 except SystemExit, _e: raise _e except: traceback.print_exc() error(misc.get_traceback_message()) sys.exit(99)