Skip to content

Commit 7ba4803

Browse files
committed
Client return errors for some bad data
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.
1 parent 53c5677 commit 7ba4803

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

rustygear/src/conn.rs

+5-16
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,11 @@ impl ConnHandler {
155155
known: bytes2bool(&next_field(&mut req.data)),
156156
running: bytes2bool(&next_field(&mut req.data)),
157157
numerator: String::from_utf8(next_field(&mut req.data).to_vec())?.parse()?,
158-
denominator: String::from_utf8(next_field(&mut req.data).to_vec())
159-
.unwrap()
160-
.parse()
161-
.unwrap(),
158+
denominator: String::from_utf8(next_field(&mut req.data).to_vec())?.parse()?,
162159
waiting: 0,
163160
};
164161
if req.ptype == STATUS_RES_UNIQUE {
165-
js.waiting = String::from_utf8(next_field(&mut req.data).to_vec())
166-
.unwrap()
167-
.parse()
168-
.unwrap();
162+
js.waiting = String::from_utf8(next_field(&mut req.data).to_vec())?.parse()?;
169163
}
170164
let tx = self.client_data.status_res_tx();
171165
runtime::Handle::current().spawn(async move { tx.send(js).await });
@@ -206,14 +200,9 @@ impl ConnHandler {
206200
},
207201
WORK_FAIL => WorkUpdate::Fail(handle),
208202
WORK_STATUS => {
209-
let numerator: usize = String::from_utf8((&payload).to_vec())
210-
.unwrap()
211-
.parse()
212-
.unwrap();
213-
let denominator: usize = String::from_utf8(next_field(&mut data).to_vec())
214-
.unwrap()
215-
.parse()
216-
.unwrap();
203+
let numerator: usize = String::from_utf8((&payload).to_vec())?.parse()?;
204+
let denominator: usize =
205+
String::from_utf8(next_field(&mut data).to_vec())?.parse()?;
217206
WorkUpdate::Status {
218207
handle: handle,
219208
numerator: numerator,

0 commit comments

Comments
 (0)