Improve error messages for not finding LBA sources
This commit is contained in:
parent
1dd145abea
commit
5d0239bfe8
|
@ -2,7 +2,7 @@ use super::{bits::{Bit, BitRange}, layout::Layout, File, FileSystemMap};
|
||||||
use super::super::encoder::LengthCalculatorFunction;
|
use super::super::encoder::LengthCalculatorFunction;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use no_comment::{IntoWithoutComments as _, languages};
|
use no_comment::{IntoWithoutComments as _, languages};
|
||||||
use tool_helper::{Error, format_if_error, read_file, format_if_error_drop_cause};
|
use tool_helper::{Error, format_if_error, read_file, read_file_to_string, format_if_error_drop_cause};
|
||||||
|
|
||||||
pub type LBANameVec = Vec<String>;
|
pub type LBANameVec = Vec<String>;
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ fn load_lba_names(lba_source: PathBuf) -> Result<LBANameVec, Error> {
|
||||||
Ok(file[start..end].to_owned())
|
Ok(file[start..end].to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
let file = std::fs::read_to_string(&lba_source)?.chars().without_comments(languages::c()).collect::<String>();
|
let file = read_file_to_string(&lba_source)?.chars().without_comments(languages::c()).collect::<String>();
|
||||||
let file = get_part_of_interest(file, &lba_source)?;
|
let file = get_part_of_interest(file, &lba_source)?;
|
||||||
let mut lba_names = Vec::new();
|
let mut lba_names = Vec::new();
|
||||||
|
|
||||||
|
|
|
@ -184,11 +184,18 @@ pub fn input_to_vec(input: Input) -> Result<Vec<u8>, Error> {
|
||||||
|
|
||||||
pub fn read_file(file_path: &PathBuf) -> Result<Vec<u8>, Error> {
|
pub fn read_file(file_path: &PathBuf) -> Result<Vec<u8>, Error> {
|
||||||
match std::fs::read(file_path) {
|
match std::fs::read(file_path) {
|
||||||
Ok(data) => {
|
Ok(data) => Ok(data),
|
||||||
Ok(data)
|
Err(error) => create_file_read_error(file_path, error),
|
||||||
},
|
}
|
||||||
Err(error) => {
|
}
|
||||||
|
|
||||||
|
pub fn read_file_to_string(file_path: &PathBuf) -> Result<String, Error> {
|
||||||
|
match std::fs::read_to_string(file_path) {
|
||||||
|
Ok(string) => Ok(string),
|
||||||
|
Err(error) => create_file_read_error(file_path, error),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_file_read_error<T>(file_path: &PathBuf, error: std::io::Error) -> Result<T, Error> {
|
||||||
Err(Error::from_text(format!("Failed reading file {} with error: \"{}\"", file_path.display(), error)))
|
Err(Error::from_text(format!("Failed reading file {} with error: \"{}\"", file_path.display(), error)))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue