From 2a936a75748c8341b4f35cfb189f53bce896f338 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sat, 3 Nov 2018 03:36:13 -0400 Subject: [PATCH] Print a nicer error message when asked to build an empty string (''). This happens sometimes, for example, if you do whatever | while read x; do redo-ifchange "$x" done and the input contains blank lines. We could ignore the request for blankness, but it seems like that situation might indicate a more serious bug in your parser, so it's probably better to just abort with a meaningful error. --- builder.py | 4 ++++ redo-ifcreate.py | 3 +++ redo-whichdo.py | 4 ++++ state.py | 3 +-- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/builder.py b/builder.py index 0681a54..15f435c 100644 --- a/builder.py +++ b/builder.py @@ -282,6 +282,10 @@ def main(targets, shouldbuildfunc): seen = {} lock = None for t in targets: + if not t: + err('cannot build the empty target ("").\n') + retcode[0] = 204 + break assert(state.is_flushed()) if t in seen: continue diff --git a/redo-ifcreate.py b/redo-ifcreate.py index 08a9cd4..b17acae 100755 --- a/redo-ifcreate.py +++ b/redo-ifcreate.py @@ -9,6 +9,9 @@ try: os.path.join(vars.PWD, vars.TARGET)) f = state.File(name=me) for t in sys.argv[1:]: + if not t: + err('cannot build the empty target ("").\n') + sys.exit(204) if os.path.exists(t): err('redo-ifcreate: error: %r already exists\n' % t) sys.exit(1) diff --git a/redo-whichdo.py b/redo-whichdo.py index bece6d1..c692e98 100755 --- a/redo-whichdo.py +++ b/redo-whichdo.py @@ -12,6 +12,10 @@ if len(sys.argv[1:]) != 1: sys.exit(1) want = sys.argv[1] +if not want: + err('cannot build the empty target ("").\n') + sys.exit(204) + abswant = os.path.abspath(want) for dodir,dofile,basedir,basename,ext in paths.possible_do_files(abswant): dopath = os.path.join('/', dodir, dofile) diff --git a/state.py b/state.py index dd490db..c857ebf 100644 --- a/state.py +++ b/state.py @@ -189,8 +189,7 @@ class File(object): row = d.execute(q, l).fetchone() if not row: if not name: - raise Exception('File with id=%r not found and ' - 'name not given' % id) + raise Exception('No file with id=%r name=%r' % (id, name)) try: _write('insert into Files (name) values (?)', [name]) except sqlite3.IntegrityError: