mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-02 02:10:39 +08:00
Catch and rethrow parse errors, showing a log entry and a GUI error.
This commit is contained in:
parent
536124072d
commit
5f68ce4e7d
@ -195,7 +195,14 @@ sub load_config {
|
|||||||
Slic3r::GUI::show_error(undef, "The selected preset does not exist anymore (" . $self->file . ").");
|
Slic3r::GUI::show_error(undef, "The selected preset does not exist anymore (" . $self->file . ").");
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
my $external_config = Slic3r::Config->load($self->file);
|
my $external_config = "";
|
||||||
|
eval {
|
||||||
|
$external_config = Slic3r::Config->load($self->file);
|
||||||
|
} or do {
|
||||||
|
# Catch exception from the XS load
|
||||||
|
Slic3r::GUI::show_error(undef, "The selected preset failed to load.");
|
||||||
|
return undef;
|
||||||
|
};
|
||||||
if (!@keys) {
|
if (!@keys) {
|
||||||
$self->_config($external_config);
|
$self->_config($external_config);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "ConfigBase.hpp"
|
#include "ConfigBase.hpp"
|
||||||
|
#include "Log.hpp"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@ -618,7 +619,13 @@ ConfigBase::load(const std::string &file)
|
|||||||
namespace pt = boost::property_tree;
|
namespace pt = boost::property_tree;
|
||||||
pt::ptree tree;
|
pt::ptree tree;
|
||||||
boost::nowide::ifstream ifs(file);
|
boost::nowide::ifstream ifs(file);
|
||||||
pt::read_ini(ifs, tree);
|
try {
|
||||||
|
pt::read_ini(ifs, tree);
|
||||||
|
} catch(std::exception& ex) {
|
||||||
|
// Log or error string stating that the data read is corrupt
|
||||||
|
Log::error("Config") << "Error reading ini " << file << ":" << ex.what() << "\n";
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
BOOST_FOREACH(const pt::ptree::value_type &v, tree) {
|
BOOST_FOREACH(const pt::ptree::value_type &v, tree) {
|
||||||
try {
|
try {
|
||||||
t_config_option_key opt_key = v.first;
|
t_config_option_key opt_key = v.first;
|
||||||
|
@ -26,10 +26,18 @@ class _Log {
|
|||||||
public:
|
public:
|
||||||
static std::unique_ptr<_Log> make_log() {
|
static std::unique_ptr<_Log> make_log() {
|
||||||
std::unique_ptr<_Log> tmp {new _Log()};
|
std::unique_ptr<_Log> tmp {new _Log()};
|
||||||
|
tmp->_inclusive_levels = true;
|
||||||
|
tmp->set_level(log_t::ERR);
|
||||||
|
tmp->set_level(log_t::FERR);
|
||||||
|
tmp->set_level(log_t::WARN);
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
static std::unique_ptr<_Log> make_log(std::ostream& out) {
|
static std::unique_ptr<_Log> make_log(std::ostream& out) {
|
||||||
std::unique_ptr<_Log> tmp {new _Log(out)};
|
std::unique_ptr<_Log> tmp {new _Log(out)};
|
||||||
|
tmp->_inclusive_levels = true;
|
||||||
|
tmp->set_level(log_t::ERR);
|
||||||
|
tmp->set_level(log_t::FERR);
|
||||||
|
tmp->set_level(log_t::WARN);
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
void fatal_error(const std::string& topic, const std::string& message);
|
void fatal_error(const std::string& topic, const std::string& message);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user