diff --git a/src/slic3r.cpp b/src/slic3r.cpp index f96b058624..bbec6a5cf6 100644 --- a/src/slic3r.cpp +++ b/src/slic3r.cpp @@ -8,6 +8,7 @@ #include #include #include +#include "boost/filesystem.hpp" using namespace Slic3r; @@ -33,8 +34,18 @@ main(const int argc, const char **argv) // load config files supplied via --load for (std::vector::const_iterator file = cli_config.load.values.begin(); file != cli_config.load.values.end(); ++file) { + if (!boost::filesystem::exists(*file)) { + std::cout << "No such file: " << *file << std::endl; + exit(1); + } + DynamicPrintConfig c; - c.load(*file); + try { + c.load(*file); + } catch (std::exception &e) { + std::cout << "Error while reading config file: " << e.what() << std::endl; + exit(1); + } c.normalize(); print_config.apply(c); } @@ -50,9 +61,19 @@ main(const int argc, const char **argv) // read input file(s) if any std::vector models; for (t_config_option_keys::const_iterator it = input_files.begin(); it != input_files.end(); ++it) { + if (!boost::filesystem::exists(*it)) { + std::cout << "No such file: " << *it << std::endl; + exit(1); + } + Model model; // TODO: read other file formats with Model::read_from_file() - Slic3r::IO::STL::read(*it, &model); + try { + Slic3r::IO::STL::read(*it, &model); + } catch (std::exception &e) { + std::cout << *it << ": " << e.what() << std::endl; + exit(1); + } if (model.objects.empty()) { printf("Error: file is empty: %s\n", it->c_str()); diff --git a/xs/src/libslic3r/IO.cpp b/xs/src/libslic3r/IO.cpp index 4a44cf23c7..9aabe0c45e 100644 --- a/xs/src/libslic3r/IO.cpp +++ b/xs/src/libslic3r/IO.cpp @@ -8,8 +8,12 @@ namespace Slic3r { namespace IO { bool STL::read(std::string input_file, TriangleMesh* mesh) { - mesh->ReadSTLFile(input_file); - mesh->check_topology(); + try { + mesh->ReadSTLFile(input_file); + mesh->check_topology(); + } catch (...) { + throw std::runtime_error("Error while reading STL file"); + } return true; } diff --git a/xs/src/libslic3r/TriangleMesh.cpp b/xs/src/libslic3r/TriangleMesh.cpp index 26432c5691..c0a2063cd6 100644 --- a/xs/src/libslic3r/TriangleMesh.cpp +++ b/xs/src/libslic3r/TriangleMesh.cpp @@ -69,6 +69,7 @@ TriangleMesh::~TriangleMesh() { void TriangleMesh::ReadSTLFile(const std::string &input_file) { stl_open(&stl, input_file.c_str()); + if (this->stl.error != 0) throw std::runtime_error("Failed to read STL file"); } void