-
Notifications
You must be signed in to change notification settings - Fork 4
Closed
Labels
1 weekProjection of 1 week for this issue to be completed.Projection of 1 week for this issue to be completed.QuestionFurther information is requestedFurther information is requested
Description
Issue / Question:
Currently, we do not use results, and as a result, a simple function such as u32::compose(&[0, 0, 0, 1], &mut 0) may panic, and kill the main thread. We expect a possible error here therefore it should NOT terminate the main thread, but rather just error in console, with a description of what happened.
Proposals / Details:
In places where an unwrap or any function that has the potential to voluntarily panic we should be using results. Consider the following potentially erroneous code:
fn do_read(some_bytes: &[u8]) -> String {
// read the first byte (length) of the string.
let length = some_bytes[0];
// now read for length
let contents = &some_bytes(1..length);
String::from_utf8(contents).unwrap()
}This proposal would change the potentially erroneous code above to:
fn do_read(some_bytes: &[u8]) -> Result<String, ErrorEnum> {
// read the first byte (length) of the string.
let length = some_bytes[0]?;
// now read for length
let contents = &some_bytes(1..length);
String::from_utf8(contents)?
}Metadata
Metadata
Assignees
Labels
1 weekProjection of 1 week for this issue to be completed.Projection of 1 week for this issue to be completed.QuestionFurther information is requestedFurther information is requested