gabrielfalcao/lettuce — Issue #221: Fix handling SystemExit in Runner().run()
Author: haypo
Created: 2012-01-17 16:20:58+00:00
State: open

Hi, Runner.run() method has a generic error handler ("except:") which tries to dump the traceback using traceback.print_exc(), but the traceback module is never imported and so the exception is completly ignored.

Here is a patch to simplify the error handling. It replaces the generic "except:" by "except Exception, err:" to not catch SystemExit or KeyboardInterrupt anymore (at least on Python 2.5+).

```
diff --git a/lettuce/__init__.py b/lettuce/__init__.py
index 3e1d473..f28911c 100644
--- a/lettuce/__init__.py
+++ b/lettuce/__init__.py
@@ -128,41 +128,33 @@ class Runner(object):
self.output.print_no_features_found(self.loader.base_dir)
return

- failed = False
try:
for filename in features_files:
feature = Feature.from_file(filename)
results.append(
feature.run(self.scenarios))
-
except exceptions.LettuceSyntaxError, e:
sys.stderr.write(e.msg)
- failed = True
- except:
- e = sys.exc_info()[1]
- print "Died with %s" % str(e)
- traceback.print_exc()
- failed = True
-
- finally:
- if failed:
- raise SystemExit(2)
-
- total = TotalResult(results)
-
- call_hook('after', 'all', total)
-
- finished_at = datetime.now()
- time_took = finished_at - started_at
-
- hours = time_took.seconds / 60 / 60
- minutes = time_took.seconds / 60
- seconds = time_took.seconds
- if hours:
- print "(finished within %d hours)" % hours
- elif minutes:
- print "(finished within %d minutes)" % minutes
- elif seconds:
- print "(finished within %d seconds)" % seconds
-
- return total
+ raise SystemExit(2)
+ except Exception, err:
+ print "Died with [%s] %s" % (type(err), str(err))
+ raise SystemExit(2)
+
+ total = TotalResult(results)
+
+ call_hook('after', 'all', total)
+
+ finished_at = datetime.now()
+ time_took = finished_at - started_at
+
+ hours = time_took.seconds / 60 / 60
+ minutes = time_took.seconds / 60
+ seconds = time_took.seconds
+ if hours:
+ print "(finished within %d hours)" % hours
+ elif minutes:
+ print "(finished within %d minutes)" % minutes
+ elif seconds:
+ print "(finished within %d seconds)" % seconds
+
+ return total
```