diff --git a/html/index.js b/html/index.js index 3b49f5f..65ffc49 100644 --- a/html/index.js +++ b/html/index.js @@ -171,6 +171,10 @@ async function clickCount() { } } + if (evt.data.type === 'stv_exception') { + window.alert('An error occurred while counting the votes:\n\n' + evt.data.message); + } + if (evt.data.type === 'init') { election = evt.data.election; diff --git a/html/worker.js b/html/worker.js index afd1b15..c369ede 100644 --- a/html/worker.js +++ b/html/worker.js @@ -101,6 +101,10 @@ function stepElection() { // Signals we require input to break a tie postMessage({'type': 'require_input', 'message': ex.message}); break; + } else if (py.isinstance(ex, py.pyRCV2.method.base_stv.STVException)) { + console.error(ex); + postMessage({'type': 'stv_exception', 'message': ex.message}); + break; } else { console.error(ex); throw ex; diff --git a/pyRCV2/method/base_stv.py b/pyRCV2/method/base_stv.py index e24120b..ffb167a 100644 --- a/pyRCV2/method/base_stv.py +++ b/pyRCV2/method/base_stv.py @@ -49,7 +49,9 @@ def groupby(iterable, keyfunc): return groups class STVException(Exception): - pass + def __init__(self, message): + Exception.__init__(self) + self.message = message class BaseSTVCounter: """ @@ -635,7 +637,7 @@ class BaseSTVCounter: if result is not None: return result - raise Exception('Unable to resolve tie') + raise STVException('Unable to resolve tie') def choose_highest(self, l): """ @@ -659,7 +661,7 @@ class BaseSTVCounter: if result is not None: return result - raise Exception('Unable to resolve tie') + raise STVException('Unable to resolve tie') def round_votes(self, num): if self.options['round_votes'] is None: