Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion libsymmetrix/source/mace.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <iostream> //TODO
#include <fstream>
#include <stdexcept>
#include <numbers>
#include <numeric>

Expand Down Expand Up @@ -906,7 +907,16 @@ void MACE::load_from_json(
const std::string filename)
{
std::ifstream f(filename);
nlohmann::json file = nlohmann::json::parse(f);
if (!f) {
throw std::runtime_error("Could not open model file: " + filename);
}
nlohmann::json file;
try {
file = nlohmann::json::parse(f);
} catch (const nlohmann::json::parse_error& e) {
throw std::runtime_error(
"Failed to parse model file '" + filename + "': " + e.what());
}

// Basic model information
num_elements = file["num_elements"];
Expand Down
12 changes: 11 additions & 1 deletion libsymmetrix/source/mace_kokkos.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <fstream>
#include <stdexcept>
#include <numbers>

// TODO: remove some of these headers?
Expand Down Expand Up @@ -1545,7 +1546,16 @@ template <typename Precision>
void MACEKokkos<Precision>::load_from_json(std::string filename)
{
std::ifstream f(filename);
nlohmann::json file = nlohmann::json::parse(f);
if (!f) {
throw std::runtime_error("Could not open model file: " + filename);
}
nlohmann::json file;
try {
file = nlohmann::json::parse(f);
} catch (const nlohmann::json::parse_error& e) {
throw std::runtime_error(
"Failed to parse model file '" + filename + "': " + e.what());
}

// Basic model information
num_elements = file["num_elements"];
Expand Down