From 93278aae715038bd26a9e6bd9e657e9398d1914c Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer Date: Thu, 31 Dec 2009 12:20:41 +0100 Subject: [PATCH] convert-ly: Raise an error message if version number is not a three-entry tuple This fixes crashes with things like \version "2.10" or \version "2.10.4.3.21" and instead gracefully reminds the user that version strings should have a form like `2.8.12' --- scripts/convert-ly.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/convert-ly.py b/scripts/convert-ly.py index f1d90f2641..cf82b029cf 100644 --- a/scripts/convert-ly.py +++ b/scripts/convert-ly.py @@ -204,12 +204,16 @@ def guess_lilypond_version (input): else: return '' -class FatalConversionError: +class FatalConversionError (Exception): pass -class UnknownVersion: +class UnknownVersion (Exception): pass +class InvalidVersion (Exception): + def __init__ (self, version): + self.version = version + def do_one_file (infile_name): ly.stderr_write (_ ("Processing `%s\'... ") % infile_name) sys.stderr.write ('\n') @@ -236,6 +240,9 @@ def do_one_file (infile_name): else: to_version = latest_version () + if len (from_version) != 3: + raise InvalidVersion (".".join ([str(n) for n in from_version])) + (last, result) = do_conversion (input, from_version, to_version) @@ -304,14 +311,18 @@ def main (): if f == '-': f = '' elif not os.path.isfile (f): - error (_ ("cannot open file: `%s'") % f) + error (_ ("%s: Unable to open file") % f) if len (files) == 1: sys.exit (1) continue try: do_one_file (f) except UnknownVersion: - error (_ ("cannot determine version for `%s'. Skipping") % f) + error (_ ("%s: Unable to determine version. Skipping") % f) + except InvalidVersion as ex: + error (_ ("%s: Invalid version string `%s' \n" + "Valid version strings consist of three numbers, " + "separated by dots, e.g. `2.8.12'") % (f, ex.version) ) sys.stderr.write ('\n') -- 2.39.2