Improve error handling of loading Slic3r profiles.
This commit is contained in:
parent
bb2b180ecc
commit
3c0cd3cbc8
@ -93,9 +93,15 @@ sub OnInit {
|
||||
$self->{preset_bundle}->set_default_suppressed($self->{app_config}->get('no_defaults') ? 1 : 0);
|
||||
eval {
|
||||
$self->{preset_bundle}->load_presets(Slic3r::data_dir);
|
||||
$self->{preset_bundle}->load_selections($self->{app_config});
|
||||
$run_wizard = 1 if $self->{preset_bundle}->has_defauls_only;
|
||||
};
|
||||
if ($@) {
|
||||
warn $@ . "\n";
|
||||
show_error(undef, $@);
|
||||
}
|
||||
eval {
|
||||
$self->{preset_bundle}->load_selections($self->{app_config});
|
||||
};
|
||||
$run_wizard = 1 if $self->{preset_bundle}->has_defauls_only;
|
||||
|
||||
# application frame
|
||||
Wx::Image::AddHandler(Wx::PNGHandler->new);
|
||||
|
@ -119,10 +119,10 @@ DynamicPrintConfig& Preset::load(const std::vector<std::string> &keys)
|
||||
try {
|
||||
this->config.load_from_ini(this->file);
|
||||
Preset::normalize(this->config);
|
||||
} catch (const std::ifstream::failure&) {
|
||||
throw std::runtime_error(std::string("The selected preset does not exist anymore: ") + this->file);
|
||||
} catch (const std::runtime_error&) {
|
||||
throw std::runtime_error(std::string("Failed loading the preset file: ") + this->file);
|
||||
} catch (const std::ifstream::failure &err) {
|
||||
throw std::runtime_error(std::string("The selected preset cannot be loaded: ") + this->file + "\n\tReason: " + err.what());
|
||||
} catch (const std::runtime_error &err) {
|
||||
throw std::runtime_error(std::string("Failed loading the preset file: ") + this->file + "\n\tReason: " + err.what());
|
||||
}
|
||||
}
|
||||
this->loaded = true;
|
||||
@ -250,6 +250,7 @@ void PresetCollection::load_presets(const std::string &dir_path, const std::stri
|
||||
m_dir_path = dir.string();
|
||||
m_presets.erase(m_presets.begin()+1, m_presets.end());
|
||||
t_config_option_keys keys = this->default_preset().config.keys();
|
||||
std::string errors_cummulative;
|
||||
for (auto &dir_entry : boost::filesystem::directory_iterator(dir))
|
||||
if (boost::filesystem::is_regular_file(dir_entry.status()) && boost::algorithm::iends_with(dir_entry.path().filename().string(), ".ini")) {
|
||||
std::string name = dir_entry.path().filename().string();
|
||||
@ -260,12 +261,15 @@ void PresetCollection::load_presets(const std::string &dir_path, const std::stri
|
||||
preset.file = dir_entry.path().string();
|
||||
preset.load(keys);
|
||||
m_presets.emplace_back(preset);
|
||||
} catch (const boost::filesystem::filesystem_error &err) {
|
||||
|
||||
} catch (const std::runtime_error &err) {
|
||||
errors_cummulative += err.what();
|
||||
errors_cummulative += "\n";
|
||||
}
|
||||
}
|
||||
std::sort(m_presets.begin() + 1, m_presets.end());
|
||||
this->select_preset(first_visible_idx());
|
||||
if (! errors_cummulative.empty())
|
||||
throw std::runtime_error(errors_cummulative);
|
||||
}
|
||||
|
||||
// Load a preset from an already parsed config file, insert it into the sorted sequence of presets
|
||||
|
@ -78,10 +78,25 @@ void PresetBundle::setup_directories()
|
||||
|
||||
void PresetBundle::load_presets(const std::string &dir_path)
|
||||
{
|
||||
this->prints .load_presets(dir_path, "print");
|
||||
std::string errors_cummulative;
|
||||
try {
|
||||
this->prints.load_presets(dir_path, "print");
|
||||
} catch (const std::runtime_error &err) {
|
||||
errors_cummulative += err.what();
|
||||
}
|
||||
try {
|
||||
this->filaments.load_presets(dir_path, "filament");
|
||||
this->printers .load_presets(dir_path, "printer");
|
||||
} catch (const std::runtime_error &err) {
|
||||
errors_cummulative += err.what();
|
||||
}
|
||||
try {
|
||||
this->printers.load_presets(dir_path, "printer");
|
||||
} catch (const std::runtime_error &err) {
|
||||
errors_cummulative += err.what();
|
||||
}
|
||||
this->update_multi_material_filament_presets();
|
||||
if (! errors_cummulative.empty())
|
||||
throw std::runtime_error(errors_cummulative);
|
||||
}
|
||||
|
||||
static inline std::string remove_ini_suffix(const std::string &name)
|
||||
@ -233,10 +248,10 @@ void PresetBundle::load_config_file(const std::string &path)
|
||||
try {
|
||||
boost::nowide::ifstream ifs(path);
|
||||
boost::property_tree::read_ini(ifs, tree);
|
||||
} catch (const std::ifstream::failure&) {
|
||||
throw std::runtime_error(std::string("The config file cannot be loaded: ") + path);
|
||||
} catch (const std::runtime_error&) {
|
||||
throw std::runtime_error(std::string("Failed loading the preset file: ") + path);
|
||||
} catch (const std::ifstream::failure &err) {
|
||||
throw std::runtime_error(std::string("The config file cannot be loaded: ") + path + "\n\tReason: " + err.what());
|
||||
} catch (const std::runtime_error &err) {
|
||||
throw std::runtime_error(std::string("Failed loading the preset file: ") + path + "\n\tReason: " + err.what());
|
||||
}
|
||||
|
||||
// 2) Continue based on the type of the configuration file.
|
||||
|
@ -111,7 +111,7 @@ PresetCollection::arrayref()
|
||||
try {
|
||||
THIS->load_presets(dir_path);
|
||||
} catch (std::exception& e) {
|
||||
croak("Loading of Slic3r presets from %s failed:\n%s\n", dir_path, e.what());
|
||||
croak("Loading of Slic3r presets from %s failed.\n\n%s\n", dir_path, e.what());
|
||||
}
|
||||
%};
|
||||
void load_config_file(const char *path)
|
||||
|
Loading…
Reference in New Issue
Block a user