Skip to content

Exit gracefully if all declared candidates fall beneath minimum vote threshold#608

Merged
tarheel merged 7 commits into
developfrom
nobody
Aug 17, 2022
Merged

Exit gracefully if all declared candidates fall beneath minimum vote threshold#608
tarheel merged 7 commits into
developfrom
nobody

Conversation

@tarheel
Copy link
Copy Markdown
Contributor

@tarheel tarheel commented Aug 8, 2022

Fixes #553.

I didn't add a test case because I don't believe we have any support (yet) for tests that confirm a failed tabulation.

Copy link
Copy Markdown
Contributor

@HEdingfield HEdingfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naisu.

newWinnerSet = runTabulationForConfig(config, castVoteRecords);
} catch (TabulationCancelledException exception) {
Logger.severe("Tabulation was cancelled by the user!");
Logger.severe(exception.getMessage());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and below: I think you might be better off just logging exception, since that should include the message and additional useful info as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want other info; the purpose of this exception class is to communicate a specific message to the user in the output.

Copy link
Copy Markdown
Collaborator

@tamird tamird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems we need a test.

Comment thread src/main/java/network/brightspots/rcv/Tabulator.java
Copy link
Copy Markdown
Contributor Author

@tarheel tarheel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems we need a test.

Not sure whether you saw my comment in the PR description: "I didn't add a test case because I don't believe we have any support (yet) for tests that confirm a failed tabulation."

Ideally, yes, we would have support for that kind of test, but I don't think it's worth doing at the moment. (Or at least I can't prioritize it right now.)

newWinnerSet = runTabulationForConfig(config, castVoteRecords);
} catch (TabulationCancelledException exception) {
Logger.severe("Tabulation was cancelled by the user!");
Logger.severe(exception.getMessage());
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want other info; the purpose of this exception class is to communicate a specific message to the user in the output.

Comment thread src/main/java/network/brightspots/rcv/Tabulator.java
@tamird
Copy link
Copy Markdown
Collaborator

tamird commented Aug 8, 2022

Yep, I saw. I'm not sure how to review this in the absence of a test.

@tarheel
Copy link
Copy Markdown
Contributor Author

tarheel commented Aug 8, 2022

OK, I removed the default constructor.

Regarding review: I did test it manually and confirmed that it aborts with the correct message if this situation occurs. So I think that suffices for now.

// One edge case: if everyone is below the threshold, we can't proceed. This would only
// happen in the first or (if we drop undeclared write-ins first) second round.
if (eliminated.size() == config.getNumDeclaredCandidates()) {
Logger.severe("Tabulation can't proceed because all declared candidates are below "
Copy link
Copy Markdown
Contributor

@moldover moldover Aug 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "Tabulation complete because..." ... the "can't proceed" language implies something is wrong, when in fact this is a normal (if edge) case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should consider this to be a "normal" case. Instead of producing winners and generating output files, we're aborting.

if (eliminated.size() == config.getNumDeclaredCandidates()) {
Logger.severe("Tabulation can't proceed because all declared candidates are below "
+ "the minimum vote threshold.");
throw new TabulationCancelledException(false);
Copy link
Copy Markdown
Contributor

@moldover moldover Aug 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really cancelled, right? It's just ending sooner than we thought. How about changing it to a TabulationException if it's going to server this purpose?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be more on board with "aborted" instead of "cancelled"? I think that captures both situations where this exception is used (giving up because no one meets the threshold or exiting because the user clicked a Cancel button). Just TabulationException is also OK, but I'd prefer to be more specific.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, sounds good.

Copy link
Copy Markdown
Contributor

@HEdingfield HEdingfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whether you saw my comment in the PR description: "I didn't add a test case because I don't believe we have any support (yet) for tests that confirm a failed tabulation."

Ideally, yes, we would have support for that kind of test, but I don't think it's worth doing at the moment. (Or at least I can't prioritize it right now.)

Would you mind adding an issue for this, pointing to this PR?

@tarheel
Copy link
Copy Markdown
Contributor Author

tarheel commented Aug 10, 2022

Would you mind adding an issue for this, pointing to this PR?

Upon further reflection... it might not be a big deal to add a test for this. I'll follow up in this PR.

@tarheel tarheel force-pushed the nobody branch 2 times, most recently from 386f5f5 to 207ee09 Compare August 16, 2022 06:57
@tarheel
Copy link
Copy Markdown
Contributor Author

tarheel commented Aug 16, 2022

Added a test here also. It was awkward to find a way to make the test work, but I think the solution I came up with isn't... terrible.

@moldover moldover self-requested a review August 17, 2022 02:13
tabulate(null);
}

void tabulate(List<String> exceptionsEncountered) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just have this return the List? That's a more typical api for error codes and then you don't need to do all the checks for if (exceptionsEncountered != null) here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also get rid of the wrapper methods

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with that approach also. I was thinking it would be weird, but upon further reflection, I guess it's fine.

@tarheel tarheel deleted the nobody branch August 17, 2022 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

silent failure if no candidate meets minimum threshold

4 participants