Skip to content

Commit 5a07aab

Browse files
authored
Merge pull request #12569 from evva-sfw/feature/mbed-error-weak
Replace with weak mbed_error_hook implementation (deprecate the hook function)
2 parents 4c6e59d + 75f8c70 commit 5a07aab

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

platform/mbed_error.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,15 @@ MBED_NORETURN void error(const char *format, ...) MBED_PRINTF(1, 2);
950950
*/
951951
typedef void (*mbed_error_hook_t)(const mbed_error_ctx *error_ctx);
952952

953+
/**
954+
* Callback/Error hook function. If application implementation needs to receive this callback when an error is reported,
955+
* mbed_error_hook function should be overridden with custom implementation. When an error happens in the system error handling
956+
* implementation will invoke this callback with the mbed_error_status_t reported and the error context at the time of error.
957+
* @param error_ctx Error context structure associated with this error.
958+
* @return void
959+
*
960+
*/
961+
void mbed_error_hook(const mbed_error_ctx *error_context);
953962

954963
/**
955964
* Callback function for reporting error context during boot up. When MbedOS error handling system detects a fatal error
@@ -1087,8 +1096,10 @@ MBED_NORETURN mbed_error_status_t mbed_error(mbed_error_status_t error_status, c
10871096
* mbed_set_error_hook( my_custom_error_hook )
10881097
*
10891098
* @endcode
1090-
* @note The erro hook function implementation should be re-entrant.
1099+
* @note The error hook function implementation should be re-entrant.
10911100
*
1101+
* @deprecated You should use an overridden mbed_error_hook() function if you like to catch errors in your application.
1102+
* With mbed_set_error_hook() it is not possible to catch errors before your application started.
10921103
*/
10931104
mbed_error_status_t mbed_set_error_hook(mbed_error_hook_t custom_error_hook);
10941105

platform/source/mbed_error.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,20 @@ static mbed_error_status_t handle_error(mbed_error_status_t error_status, unsign
197197
//Call the error hook if available
198198
if (error_hook != NULL) {
199199
error_hook(&last_error_ctx);
200+
} else {
201+
mbed_error_hook(&last_error_ctx);
200202
}
201203

202204
core_util_critical_section_exit();
203205

204206
return MBED_SUCCESS;
205207
}
206208

209+
WEAK void mbed_error_hook(const mbed_error_ctx *error_context)
210+
{
211+
//Dont do anything here, let application override this if required.
212+
}
213+
207214
WEAK void mbed_error_reboot_callback(mbed_error_ctx *error_context)
208215
{
209216
//Dont do anything here, let application override this if required.
@@ -323,6 +330,7 @@ WEAK MBED_NORETURN mbed_error_status_t mbed_error(mbed_error_status_t error_stat
323330
}
324331

325332
//Register an application defined callback with error handling
333+
MBED_DEPRECATED("Use an overridden mbed_error_hook() function instead")
326334
mbed_error_status_t mbed_set_error_hook(mbed_error_hook_t error_hook_in)
327335
{
328336
//register the new hook/callback

0 commit comments

Comments
 (0)