Display error message in JS version when known STVException
This commit is contained in:
parent
6b5c188668
commit
0b3651d450
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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:
|
||||
|
Reference in New Issue
Block a user