Skip to content

Commit

Permalink
Client return errors for some bad data
Browse files Browse the repository at this point in the history
A poorly constructed client may send the wrong thing at times. Rather
than panic, we should be returning these as normal errors that workers
or clients can handle.
  • Loading branch information
SpamapS committed Jun 17, 2024
1 parent 53c5677 commit 7ba4803
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions rustygear/src/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,11 @@ impl ConnHandler {
known: bytes2bool(&next_field(&mut req.data)),
running: bytes2bool(&next_field(&mut req.data)),
numerator: String::from_utf8(next_field(&mut req.data).to_vec())?.parse()?,
denominator: String::from_utf8(next_field(&mut req.data).to_vec())
.unwrap()
.parse()
.unwrap(),
denominator: String::from_utf8(next_field(&mut req.data).to_vec())?.parse()?,
waiting: 0,
};
if req.ptype == STATUS_RES_UNIQUE {
js.waiting = String::from_utf8(next_field(&mut req.data).to_vec())
.unwrap()
.parse()
.unwrap();
js.waiting = String::from_utf8(next_field(&mut req.data).to_vec())?.parse()?;
}
let tx = self.client_data.status_res_tx();
runtime::Handle::current().spawn(async move { tx.send(js).await });
Expand Down Expand Up @@ -206,14 +200,9 @@ impl ConnHandler {
},
WORK_FAIL => WorkUpdate::Fail(handle),
WORK_STATUS => {
let numerator: usize = String::from_utf8((&payload).to_vec())
.unwrap()
.parse()
.unwrap();
let denominator: usize = String::from_utf8(next_field(&mut data).to_vec())
.unwrap()
.parse()
.unwrap();
let numerator: usize = String::from_utf8((&payload).to_vec())?.parse()?;
let denominator: usize =
String::from_utf8(next_field(&mut data).to_vec())?.parse()?;
WorkUpdate::Status {
handle: handle,
numerator: numerator,
Expand Down

0 comments on commit 7ba4803

Please sign in to comment.