2626#include < utility>
2727#include < vector>
2828
29+ #include " exceptions/exceptions.hpp"
2930#include " map_types/base_mapping.hpp"
3031#include " map_types/custom_mapping.hpp"
3132#include " map_types/data_source_mapping.hpp"
@@ -136,7 +137,7 @@ std::string libtokamap::TypedDataArray::to_string() const
136137 print<double >(out, m_buffer, m_size);
137138 break ;
138139 default :
139- throw std::runtime_error {" unhandled data type: '" + ::to_string (m_type_index) + " '" };
140+ throw libtokamap::DataTypeError {" unhandled data type: '" + ::to_string (m_type_index) + " '" };
140141 }
141142 out << " }" ;
142143 return out.str ();
@@ -156,7 +157,7 @@ void libtokamap::MappingHandler::init(const nlohmann::json& config)
156157 }
157158
158159 if (!config.contains (" mapping_directory" )) {
159- throw std::runtime_error {" mapping_directory not specified in config" };
160+ throw libtokamap::ConfigurationError {" mapping_directory not specified in config" };
160161 }
161162 m_mapping_dir = config.at (" mapping_directory" ).get <std::string>();
162163
@@ -181,7 +182,7 @@ libtokamap::TypedDataArray libtokamap::MappingHandler::map(const std::string& ma
181182 std::deque<std::string_view> path_tokens;
182183 libtokamap::split (path_tokens, path, " /" );
183184 if (path_tokens.empty ()) {
184- throw std::runtime_error {" IDS path could not be split" };
185+ throw libtokamap::PathError {" IDS path could not be split" };
185186 }
186187
187188 auto [indices, new_tokens] = extract_indices (path_tokens);
@@ -199,7 +200,8 @@ libtokamap::TypedDataArray libtokamap::MappingHandler::map(const std::string& ma
199200 const auto maybe_mappings = read_mappings (machine_string, ids_name, extra_attributes);
200201
201202 if (!maybe_mappings) {
202- throw std::runtime_error{" no mappings found for machine '" + machine_string + " ' and IDS '" + ids_name + " '" };
203+ throw libtokamap::MappingError{" no mappings found for machine '" + machine_string + " ' and IDS '" + ids_name +
204+ " '" };
203205 }
204206
205207 const auto & [attributes, mappings] = maybe_mappings.value ();
@@ -210,7 +212,7 @@ libtokamap::TypedDataArray libtokamap::MappingHandler::map(const std::string& ma
210212
211213 std::string const map_path = generate_map_path (new_tokens, indices, mappings, path);
212214 if (map_path.empty ()) {
213- throw std::runtime_error {" failed to find mapping for '" + path + " '" };
215+ throw libtokamap::MappingError {" failed to find mapping for '" + path + " '" };
214216 }
215217
216218 // Add request indices to globals
@@ -306,7 +308,7 @@ void libtokamap::MappingHandler::load_machine(const MachineName& machine)
306308 if (map_cfg_file) {
307309 map_cfg_file >> m_mapping_config;
308310 } else {
309- throw std::runtime_error {" Cannot open JSON mapping config file" };
311+ throw libtokamap::FileError {" Cannot open JSON mapping config file" };
310312 }
311313
312314 m_machine_register[machine] = {.mappings = {}, .attributes = {}};
@@ -329,10 +331,10 @@ nlohmann::json libtokamap::MappingHandler::load_toplevel(const MachineName& mach
329331 try {
330332 globals_file >> toplevel_globals;
331333 } catch (nlohmann::json::exception& ex) {
332- throw std::runtime_error {ex.what ()};
334+ throw libtokamap::JsonError {ex.what ()};
333335 }
334336 } else {
335- throw std::runtime_error {" Cannot open top-level globals file" };
337+ throw libtokamap::FileError {" Cannot open top-level globals file" };
336338 }
337339 return toplevel_globals;
338340}
@@ -348,13 +350,13 @@ void libtokamap::MappingHandler::load_shot_globals(const MachineName& machine, c
348350 try {
349351 globals_file >> temp_globals;
350352 } catch (nlohmann::json::exception& ex) {
351- throw std::runtime_error {ex.what ()};
353+ throw libtokamap::JsonError {ex.what ()};
352354 }
353355
354356 temp_globals.update (load_toplevel (machine));
355357 m_machine_register[machine].attributes [ids_name].map [shot] = temp_globals; // Record globals
356358 } else {
357- throw std::runtime_error {" Cannot open JSON globals file" };
359+ throw libtokamap::FileError {" Cannot open JSON globals file" };
358360 }
359361}
360362
@@ -380,12 +382,12 @@ void libtokamap::MappingHandler::load_shot_mappings(const MachineName& machine,
380382 try {
381383 map_file >> temp_mappings;
382384 } catch (nlohmann::json::exception& ex) {
383- throw std::runtime_error {ex.what ()};
385+ throw libtokamap::JsonError {ex.what ()};
384386 }
385387
386388 init_mappings (machine, ids_name, temp_mappings, shot);
387389 } else {
388- throw std::runtime_error {" Cannot open JSON mapping file" };
390+ throw libtokamap::FileError {" Cannot open JSON mapping file" };
389391 }
390392}
391393
@@ -476,13 +478,15 @@ void init_data_source_mapping(libtokamap::IDSMapRegister& map_reg, const std::st
476478 const nlohmann::json& ids_attributes, std::shared_ptr<libtokamap::RamCache>& ram_cache)
477479{
478480 if (!value.contains (" DATA_SOURCE" )) {
479- throw std::runtime_error{" required DATA_SOURCE argument not provided in DATA_SOURCE mapping '" + key + " '" };
481+ throw libtokamap::ConfigurationError{" required DATA_SOURCE argument not provided in DATA_SOURCE mapping '" +
482+ key + " '" };
480483 }
481484 std::string data_source_name = value[" DATA_SOURCE" ].get <std::string>();
482485 libtokamap::to_upper (data_source_name);
483486
484487 if (!value.contains (" ARGS" )) {
485- throw std::runtime_error{" required ARGS argument not provided in DATA_SOURCE mapping '" + key + " '" };
488+ throw libtokamap::ConfigurationError{" required ARGS argument not provided in DATA_SOURCE mapping '" + key +
489+ " '" };
486490 }
487491 auto args = value[" ARGS" ].get <libtokamap::DataSourceArgs>();
488492 auto offset = get_float_value (" OFFSET" , value, ids_attributes);
@@ -529,7 +533,7 @@ void libtokamap::MappingHandler::init_mappings(const MachineName& machine, const
529533 auto parsed_value = libtokamap::parse (value);
530534
531535 if (!parsed_value.contains (" MAP_TYPE" )) {
532- throw std::runtime_error {" required MAP_TYPE argument not found in mapping '" + key + " '" };
536+ throw libtokamap::MappingError {" required MAP_TYPE argument not found in mapping '" + key + " '" };
533537 }
534538
535539 // TODO: make this case insensitive?
0 commit comments