diff --git a/core/error.c b/core/error.c index e749b9f..3e7613b 100644 --- a/core/error.c +++ b/core/error.c @@ -719,10 +719,25 @@ static const struct b_error_definition builtin_errors[] = { "Class initialisation failure"), }; +static const struct b_error_msg builtin_msg[] = { + B_ERROR_MSG(B_MSG_TYPE_REGISTRATION_FAILURE, "Type registration failed"), + B_ERROR_MSG(B_MSG_CLASS_INIT_FAILURE, "Class initialisation failed"), + B_ERROR_MSG_TEMPLATE( + B_MSG_CLASS_SPECIFIES_UNKNOWN_INTERFACE, + "Class @[class_name] specifies an implementation for interface " + "@[interface_name] that it does not extend or inherit", + B_ERROR_TEMPLATE_PARAM( + "class_name", B_ERROR_TEMPLATE_PARAM_STRING, "%s"), + B_ERROR_TEMPLATE_PARAM( + "interface_name", B_ERROR_TEMPLATE_PARAM_STRING, "%s")), +}; + static const struct b_error_vendor builtin_vendor = { .v_name = "Blue", .v_error_definitions = builtin_errors, .v_error_definitions_length = sizeof builtin_errors, + .v_msg = builtin_msg, + .v_msg_length = sizeof builtin_msg, }; static void get_error_id( diff --git a/core/include/blue/core/macros.h b/core/include/blue/core/macros.h index 15816db..380836c 100644 --- a/core/include/blue/core/macros.h +++ b/core/include/blue/core/macros.h @@ -20,7 +20,14 @@ #define B_TYPE_CLASS_INTERFACE_BEGIN(interface_name, interface_id) \ interface_name##_class *__B_IFACE_I1(iface, __LINE__) \ = b_class_get_interface(p, interface_id); \ - if (__B_IFACE_I1(iface, __LINE__)) { \ + if (!__B_IFACE_I1(iface, __LINE__)) { \ + b_throw_error_with_msg_template( \ + B_ERRORS_BUILTIN, B_ERR_CLASS_INIT_FAILURE, \ + B_MSG_CLASS_SPECIFIES_UNKNOWN_INTERFACE, \ + B_ERROR_PARAM("class_name", b_class_get_name(p)), \ + B_ERROR_PARAM("interface_name", #interface_name)); \ + exit(-1); \ + } else { \ interface_name##_class *iface = __B_IFACE_I1(iface, __LINE__); #define B_TYPE_CLASS_INTERFACE_END(interface_name, interface_id) } #define B_INTERFACE_ENTRY(slot) iface->slot diff --git a/core/include/blue/core/status.h b/core/include/blue/core/status.h index 2629d2a..fc1175f 100644 --- a/core/include/blue/core/status.h +++ b/core/include/blue/core/status.h @@ -39,6 +39,7 @@ typedef enum b_status_msg { /* blue-object specific messages */ B_MSG_TYPE_REGISTRATION_FAILURE, B_MSG_CLASS_INIT_FAILURE, + B_MSG_CLASS_SPECIFIES_UNKNOWN_INTERFACE, } b_status_msg; BLUE_API const char *b_status_to_string(b_status status);