Commit 62fd6698 authored by major's avatar major

fix #1 - crash when ballout action is called on something not a BalloutId

parent 0cfeb8da
Pipeline #428 passed with stage
in 11 minutes and 17 seconds
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "aho-corasick"
version = "0.6.9"
......
......@@ -2,6 +2,9 @@ use std::collections::{hash_map::{DefaultHasher, Entry::{Occupied, Vacant}, Occu
use std::hash::{Hash, Hasher};
use std::ops::Deref;
use std::ops::DerefMut;
use std::convert::TryFrom;
use failure::{Error, format_err};
use chrono::{Local, NaiveDate};
......@@ -16,9 +19,12 @@ impl std::fmt::Display for BallotId {
}
}
impl<S> From<S> for BallotId where S: AsRef<str> {
fn from(s: S) -> Self {
BallotId(u32::from_str_radix(s.as_ref(), 16).unwrap())
impl TryFrom<&str> for BallotId {
type Error = Error;
fn try_from(s: &str) -> Result<Self, Self::Error> {
Ok(BallotId(u32::from_str_radix(s, 16)
.map_err(|_| format_err!("Invalid ballot ID: {}", s))?))
}
}
......
......@@ -11,6 +11,7 @@ extern crate time;
use std::collections::HashSet;
use std::fmt;
use std::iter::FromIterator;
use std::convert::TryFrom;
use clap::{Arg, SubCommand};
use itertools::Itertools;
......@@ -353,27 +354,27 @@ impl CommandModule for BoardBot {
self.members_only(response, &command.source, || {
self.vote(response,
&command.source,
BallotId::from(matches.value_of("id").unwrap()),
BallotId::try_from(matches.value_of("id").unwrap())?,
Opinion::Yes)
}),
("no", Some(matches)) =>
self.members_only(response, &command.source, || {
self.vote(response,
&command.source,
BallotId::from(matches.value_of("id").unwrap()),
BallotId::try_from(matches.value_of("id").unwrap())?,
Opinion::No)
}),
("commit", Some(matches)) =>
self.members_only(response, &command.source, || {
self.commit(response,
&command.source,
BallotId::from(matches.value_of("id").unwrap()))
BallotId::try_from(matches.value_of("id").unwrap())?)
}),
("cancel", Some(matches)) =>
self.members_only(response, &command.source, || {
self.cancel(response,
&command.source,
BallotId::from(matches.value_of("id").unwrap()))
BallotId::try_from(matches.value_of("id").unwrap())?)
}),
("search", Some(matches)) =>
self.search(response,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment