12#include "comin_logging.hpp"
13#include "comin_state.hpp"
14#include "comin_util.hpp"
24 "The underlying type of t_comin_error_code must be int for "
25 "Fortran interoperability. Recompile with "
26 "-fno-short-enums or similar.");
29using namespace std::string_view_literals;
31constexpr auto error_strings = comin::to_array<
32 std::tuple<t_comin_error_code, std::string_view>>({
38 "Callbacks cannot be registered after primary constructor."sv},
40 "Callback registration could not be completed."sv},
43 "Unable to set descriptive data function: glb2loc. Function not associated."sv},
45 "Unable to clean up descriptive data structure (finalize)."sv},
47 "Cannot set metadata outside primary constructor."sv},
50 "Unable to get metadata inside primary constructor."sv},
53 "ComIn is already initilized."sv},
55 "The host model error handler procedure cannot be found."sv},
57 "Error handler not set (setup check)."sv},
59 "Precision test failed (setup check)."sv},
61 "Variables cannot be requested after primary constructor."sv},
63 "Requested variable already exists and is exclusive."sv},
65 "Requested exclusive variable already exists."sv},
71 "Tracers need to be requested for all domains (id=-1)."sv},
73 "Sync device memory callback not set (setup check)."sv},
75 "Sync halo callback not set (setup check)."sv},
77 "Cannot get variable outside of secondary constructor."sv},
81 "Cannot halo sync a container."sv},
83 "Cannot halo sync an irregular variable."sv},
85 "Can only halo sync vars on 2D or 3D vertical grid."sv},
87 "Metadata type does not match access function."sv},
89 "Wrong type used requesting the pointer of a variable."sv},
97std::string_view
to_string(t_comin_error_code error_code) {
98 auto it = std::find_if(
99 error_strings.cbegin(), error_strings.cend(),
100 [error_code](
const auto& a) { return std::get<0>(a) == error_code; });
102 if (error_strings.cend() != it) {
103 return std::get<1>(*it);
105 return "<unknown>"sv;
109std::string_view
category(t_comin_error_code error_code) {
110 if (COMIN_SUCCESS == error_code)
112 else if (error_code < COMIN_WARNING)
114 else if (error_code < COMIN_ERROR_STATUS)
116 else if (error_code < COMIN_ERROR_FATAL)
119 return "FATAL ERROR"sv;
153 if (!comin::state.comin_host_errhandler_fct) {
155 comin::logging::message(12, routine,
": ", text);
157 MPI_Abort(MPI_COMM_WORLD, exit_no);
160 comin::state.comin_host_errhandler_fct(routine, text);
173 if (error_code == COMIN_SUCCESS)
178 if (error_code < COMIN_ERROR_STATUS) {
179 comin::logging::message(12, category,
": ", msg);
204constexpr bool check_all_error_codes_have_strings() {
207 for (
const auto& it : error_strings) {
208 if (std::get<0>(it) == code) {
222static_assert(check_all_error_codes_have_strings(),
223 "Not all error codes have error strings.");
225constexpr bool check_all_error_codes_have_one_string() {
228 for (
const auto& it : error_strings) {
229 if (std::get<0>(it) == code) {
242static_assert(check_all_error_codes_have_one_string(),
243 "Some error codes have multiple strings.");
void comin_plugin_finish_f(const char *routine, const char *fmt,...)
const char * comin_error_get_category(t_comin_error_code error_code)
void comin_error_set(t_comin_error_code error_code)
t_comin_error_code comin_error_get()
Get the current ComIn error code.
const char * comin_error_get_string(t_comin_error_code error_code)
void comin_plugin_finish(const char *routine, const char *text)
void comin_error_reset()
Reset the current ComIn error code to COMIN_SUCCESS.
const char * comin_current_get_plugin_name()
bool comin_current_get_plugin_errors_return()
int comin_state_get_error_code()
int comin_current_get_plugin_id()
t_comin_entry_point comin_current_get_ep()
void comin_state_set_error_code(int errcode)
@ COMIN_ERROR_VAR_METADATA_INCONSISTENT_TYPE
@ COMIN_ERROR_VAR_GET_CONTAINER_CAN_NOT_HALO_SYNCHRONIZED
@ COMIN_ERROR_SETUP_COMIN_ALREADY_INITIALIZED
@ COMIN_ERROR_SETUP_ERRHANDLER_NOT_ASSOCIATED
@ COMIN_ERROR_CALLBACK_EP_ID_UNKNOWN
@ COMIN_ERROR_VAR_GET_VARIABLE_NOT_FOUND
@ COMIN_ERROR_VAR_GET_IRREGULAR_VAR_CAN_NOT_HALO_SYNCHRONIZED
@ COMIN_ERROR_VAR_REQUEST_EXISTS_IS_LMODEXCLUSIVE
@ COMIN_ERROR_POINTER_NOT_ASSOCIATED
@ COMIN_ERROR_VAR_REQUEST_EXISTS_REQUEST_LMODEXCLUSIVE
@ COMIN_ERROR_VAR_SYNC_HALO_NOT_ASSOCIATED
@ COMIN_ERROR_DESCRDATA_TIMESTEPLENGTH_NOT_SET
@ COMIN_ERROR_VAR_GET_VARIABLE_WRONG_TYPE
@ COMIN_ERROR_VAR_GET_NO_DEVICE
@ COMIN_ERROR_DESCRDATA_SET_FCT_GLB2LOC
@ COMIN_ERROR_VAR_REQUEST_AFTER_PRIMARYCONSTRUCTOR
@ COMIN_ERROR_METADATA_KEY_NOT_FOUND
@ COMIN_ERROR_VAR_ITEM_NOT_ASSOCIATED
@ COMIN_ERROR_INDEX_OUT_OF_BOUNDS
@ COMIN_ERROR_SETUP_ERRHANDLER_NOT_SET
@ COMIN_ERROR_FIELD_NOT_ALLOCATED
@ COMIN_ERROR_METADATA_SET_OUTSIDE_PRIMARYCONSTRUCTOR
@ COMIN_ERROR_TRACER_REQUEST_NOT_FOR_ALL_DOMAINS
@ COMIN_ERROR_VAR_DESCRIPTOR_NOT_FOUND
@ COMIN_ERROR_VAR_SYNC_HALO_NOT_SUPPORTED_ZAXIS
@ COMIN_ERROR_VAR_SYNC_DEVICE_MEM_NOT_ASSOCIATED
@ COMIN_ERROR_SETUP_PRECISION_TEST_FAILED
@ COMIN_ERROR_CALLBACK_COMPLETE
@ COMIN_ERROR_METADATA_GET_INSIDE_PRIMARYCONSTRUCTOR
@ COMIN_ERROR_VAR_GET_OUTSIDE_SECONDARY_CONSTRUCTOR
@ COMIN_ERROR_CALLBACK_REGISTER_OUTSIDE_PRIMARYCONSTRUCTOR
@ COMIN_ERROR_SETUP_FINALIZE
@ COMIN_ERROR_DESCRDATA_FINALIZE
std::string_view to_string(t_comin_error_code error_code)
std::string_view category(t_comin_error_code error_code)