Skip to content

Commit 68e59a1

Browse files
committed
Fix for error report not printing when calling error API
1 parent 07a6ab0 commit 68e59a1

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

platform/mbed_error.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ static mbed_error_ctx first_error_ctx = {0};
5151
static mbed_error_ctx last_error_ctx = {0};
5252
static mbed_error_hook_t error_hook = NULL;
5353
static void print_error_report(mbed_error_ctx *ctx, const char *);
54+
static mbed_error_status_t handle_error(mbed_error_status_t error_status, unsigned int error_value, const char *filename, int line_number);
5455

5556
//Helper function to halt the system
5657
static void mbed_halt_system(void)
@@ -72,20 +73,23 @@ WEAK void error(const char* format, ...) {
7273
if (error_in_progress) {
7374
return;
7475
}
76+
77+
//Call handle_error/print_error_report permanently setting error_in_progress flag
78+
handle_error(MBED_ERROR_UNKNOWN, 0, NULL, 0);
79+
print_error_report(&last_error_ctx, "Fatal Run-time error");
7580
error_in_progress = 1;
7681

7782
#ifndef NDEBUG
7883
va_list arg;
7984
va_start(arg, format);
8085
mbed_error_vfprintf(format, arg);
81-
MBED_ERROR(MBED_ERROR_UNKNOWN, "Fatal Run-time Error");
8286
va_end(arg);
8387
#endif
8488
exit(1);
8589
}
8690

8791
//Set an error status with the error handling system
88-
mbed_error_status_t handle_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
92+
static mbed_error_status_t handle_error(mbed_error_status_t error_status, unsigned int error_value, const char *filename, int line_number)
8993
{
9094
mbed_error_ctx current_error_ctx;
9195

@@ -182,14 +186,14 @@ int mbed_get_error_count(void)
182186
//Sets a fatal error
183187
mbed_error_status_t mbed_warning(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
184188
{
185-
return handle_error(error_status, error_msg, error_value, filename, line_number);
189+
return handle_error(error_status, error_value, filename, line_number);
186190
}
187191

188192
//Sets a fatal error
189193
WEAK mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
190194
{
191195
//set the error reported and then halt the system
192-
if( MBED_SUCCESS != handle_error(error_status, error_msg, error_value, filename, line_number) )
196+
if( MBED_SUCCESS != handle_error(error_status, error_value, filename, line_number) )
193197
return MBED_ERROR_FAILED_OPERATION;
194198

195199
//On fatal errors print the error context/report
@@ -421,7 +425,7 @@ static void print_error_report(mbed_error_ctx *ctx, const char *error_msg)
421425
#endif //TARGET_CORTEX_M
422426
}
423427

424-
mbed_error_printf("\n-- MbedOS Error Info --");
428+
mbed_error_printf("\n-- MbedOS Error Info --\n");
425429
}
426430

427431

0 commit comments

Comments
 (0)