Error handling (#1154)

Improve error message, if model is not found
This commit is contained in:
Mohd Arsh Ali 2022-10-13 17:31:06 +05:30 committed by GitHub
parent 75db7adc28
commit d1cc3f33b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -45,18 +45,29 @@ fn main() -> anyhow::Result<()> {
let args = Args::parse();
let config = Config::load()?;
let path = config.default_path.unwrap_or_else(|| PathBuf::from(""));
let parameters = args.parameters.unwrap_or_else(Parameters::empty);
let shape_processor = ShapeProcessor {
tolerance: args.tolerance,
};
let model = if let Some(model) = args.model.or(config.default_model) {
let path_of_model = path.canonicalize().unwrap_or_default();
let model = if let Some(model) =
args.model.or(config.default_model).as_ref()
{
let mut model_path = path;
model_path.push(model);
Some(Model::from_path(model_path.clone()).with_context(|| {
format!("Failed to load model: {}", model_path.display())
if path_of_model.as_os_str().is_empty() {
format!(
"Model is not defined, can't find model defined inside the default-model also, add model like \n cargo run -- -m {}", model.display()
)
} else {
format!(
"Failed to load model: {0}\ninside default models directory: '{1}'\nCan mainly caused by: \n1. Model '{2}' can not be found inside '{1}'\n2.'{2}' can be mis-typed see inside '{1}' for a match\n3. Define model is '{2}' couldn\'t be found ((defined in command-line arguments))", model_path.display(), path_of_model.display(), model.display()
)
}
})?)
} else {
None