Handle UTF-8 Errors by returning

This commit is contained in:
Matthias Beyer 2017-08-26 19:44:29 +02:00
parent 7a7ea5c211
commit 286de656df
2 changed files with 5 additions and 4 deletions

View file

@ -22,7 +22,8 @@ generate_error_module!(
ConversionError => "Conversion Error", ConversionError => "Conversion Error",
StoreError => "Store Error", StoreError => "Store Error",
StoreIdError => "Store Id handling error", StoreIdError => "Store Id handling error",
ImportError => "Error importing" ImportError => "Error importing",
UTF8Error => "Encountered non-UTF8 characters while reading input"
); );
); );

View file

@ -48,7 +48,7 @@ impl<'a> Task<'a> {
pub fn import<R: BufRead>(store: &'a Store, mut r: R) -> Result<(Task<'a>, String, Uuid)> { pub fn import<R: BufRead>(store: &'a Store, mut r: R) -> Result<(Task<'a>, String, Uuid)> {
let mut line = String::new(); let mut line = String::new();
r.read_line(&mut line); try!(r.read_line(&mut line).map_err_into(TEK::UTF8Error));
import_task(&line.as_str()) import_task(&line.as_str())
.map_err_into(TEK::ImportError) .map_err_into(TEK::ImportError)
.and_then(|t| { .and_then(|t| {
@ -70,7 +70,7 @@ impl<'a> Task<'a> {
where R: BufRead where R: BufRead
{ {
let mut line = String::new(); let mut line = String::new();
r.read_line(&mut line); try!(r.read_line(&mut line).map_err_into(TEK::UTF8Error));
Task::get_from_string(store, line) Task::get_from_string(store, line)
} }
@ -104,7 +104,7 @@ impl<'a> Task<'a> {
/// implicitely create the task if it does not exist. /// implicitely create the task if it does not exist.
pub fn retrieve_from_import<R: BufRead>(store: &'a Store, mut r: R) -> Result<Task<'a>> { pub fn retrieve_from_import<R: BufRead>(store: &'a Store, mut r: R) -> Result<Task<'a>> {
let mut line = String::new(); let mut line = String::new();
r.read_line(&mut line); try!(r.read_line(&mut line).map_err_into(TEK::UTF8Error));
Task::retrieve_from_string(store, line) Task::retrieve_from_string(store, line)
} }