Display error message in JS version when known STVException

This commit is contained in:
RunasSudo 2021-01-04 19:34:55 +11:00
parent 6b5c188668
commit 0b3651d450
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
3 changed files with 13 additions and 3 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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: