dictionary error handling
This commit is contained in:
parent
19414d8290
commit
407f052f12
|
@ -1,5 +1,6 @@
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::io::ErrorKind;
|
||||||
|
|
||||||
use crate::db::get_db_path;
|
use crate::db::get_db_path;
|
||||||
|
|
||||||
|
@ -42,11 +43,27 @@ fn get_sym_pos_or_panic(path: &String, line: &str, sym: &str, line_number: usize
|
||||||
|
|
||||||
fn read_and_parse(path: &String) -> Vec<DictionaryEntry> {
|
fn read_and_parse(path: &String) -> Vec<DictionaryEntry> {
|
||||||
let mut result: Vec<DictionaryEntry> = Vec::new();
|
let mut result: Vec<DictionaryEntry> = Vec::new();
|
||||||
let content = fs::read_to_string(path).unwrap();
|
let content = match fs::read_to_string(path) {
|
||||||
|
Ok(string) => string,
|
||||||
|
Err(kind) => match kind.kind() {
|
||||||
|
ErrorKind::NotFound => {
|
||||||
|
println!("No dictionary file found. Assuming it's empty. Perhaps, you want to download it from my git? https://git.foxarmy.org/leca/learn-hieroglyphs");
|
||||||
|
return Vec::new();
|
||||||
|
}
|
||||||
|
ErrorKind::PermissionDenied => {
|
||||||
|
println!("Permission denied while was trying to access the dictionary.txt file. Assuming it's empty");
|
||||||
|
return Vec::new();
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
println!("Unexpected error. Can't load dictionary. Assuming it's empty");
|
||||||
|
return Vec::new();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
let content: Vec<&str> = content.split('\n').collect();
|
let content: Vec<&str> = content.split('\n').collect();
|
||||||
for (line_number, line) in content.iter().enumerate() {
|
for (line_number, line) in content.iter().enumerate() {
|
||||||
if line == &"" {
|
if *line == "" {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let hieroglyph_start = get_sym_pos_or_panic(path, line, "(", line_number) + 1;
|
let hieroglyph_start = get_sym_pos_or_panic(path, line, "(", line_number) + 1;
|
||||||
|
|
Loading…
Reference in New Issue