From 4149061ec142f767782afd4f0529dbfc0da447fc Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Fri, 7 Nov 2014 16:17:28 -0500 Subject: [PATCH] Don't throw unhandled exceptions. --- src | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src b/src index 1e856c7..295eefe 100755 --- a/src +++ b/src @@ -21,9 +21,6 @@ def rfc3339(t): def announce(msg): sys.stdout.write("src: " + msg + "\n") -def complain(msg): - sys.stderr.write("src: " + msg + "\n") - def croak(msg): sys.stderr.write("src: " + msg + "\n") sys.exit(1) @@ -39,7 +36,7 @@ pseudotime = False repodir = ".src" def do_or_die(dcmd, legend=b"", loud=False): - "Either execute a command or raise a fatal exception." + "Either execute a command or die." if legend: legend = " " + legend if debug == 0 and not loud: @@ -51,11 +48,11 @@ def do_or_die(dcmd, legend=b"", loud=False): try: retcode = subprocess.call("(" + dcmd + ")" + mute, shell=True) if retcode < 0: - complain(b"child was terminated by signal %d." % -retcode) + croak(b"child was terminated by signal %d." % -retcode) elif retcode != 0: - complain(b"child returned %d." % retcode) + croak(b"child returned %d." % retcode) except (OSError, IOError) as e: - complain(b"execution of %s%s failed: %s" % (dcmd, legend, e)) + croak(b"execution of %s%s failed: %s" % (dcmd, legend, e)) class popen_or_die: "Read or write from a subordinate process." @@ -77,14 +74,13 @@ class popen_or_die: self.fp = os.popen(self.command, self.mode) return self.fp except (OSError, IOError) as oe: - complain(b"execution of %s%s failed: %s" \ + croak(b"execution of %s%s failed: %s" \ % (self.command, self.legend, oe)) def __exit__(self, extype, value, traceback_unused): if extype: - complain(b"fatal exception in popen_or_die.") - raise extype(value) + croak(b"fatal exception in popen_or_die.") if self.fp.close() is not None: - complain(b"%s%s returned error." % (self.command, self.legend)) + croak(b"%s%s returned error." % (self.command, self.legend)) return False def capture_or_die(command): @@ -304,11 +300,11 @@ def init_method(*args): try: os.mkdir(repodir) except OSError: - complain("creation failed, check directory permissions.") + croak("creation failed, check directory permissions.") elif os.path.isdir(repodir): - complain("%s already exists." % repodir) + croak("%s already exists." % repodir) else: - complain("%s exists but is not a directory." % repodir) + croak("%s exists but is not a directory." % repodir) def preamble(cmd, args): "Common setup code." @@ -365,9 +361,9 @@ def add_method(*args): croak("add doesn't take a revision spec") for arg in args: if not os.path.exists(arg): - complain("I see no '%s' here." % arg) + croak("I see no '%s' here." % arg) elif os.path.exists("%s/%s,v" % (repodir, arg)): - complain("%s is already registered." % arg) + croak("%s is already registered." % arg) else: do_or_die("rcs -q -kb -i {0}