alxhoff / FreeRTOS-Emulator

POSIX based FreeRTOS emulator with SDL2 graphics interface and multiple async communications interfaces, aiming to make it possible to teach FreeRTOS without embedded hardware using similar processes
https://alxhoff.github.io/FreeRTOS-Emulator/
GNU General Public License v3.0
60 stars 105 forks source link

Restructured Error Handling misses SDL_GetError() output #18

Closed PhilippvK closed 4 years ago

PhilippvK commented 4 years ago

I really like your error handling using goto statements and labels to make code less redundant but by printing errors just via PRINT_ERROR() instead of logSDLError(), you do loose the information on what did specifically fail in case of working with SDL_CreateWindow() and so on.

This information is provided by SDL_GetError() which only called from logSDLError().

Do you have an idea on how to incomporate it?

Targets cdfa82be5f183b0c826e6833b00a443e8a751c06

alxhoff commented 4 years ago

I created two ,,,,urm..."sub-defines"?

#define PRINT_TTF_ERROR(msg, ...) PRINT_ERROR("[TTF Error] %s\n" #msg, (char *) TTF_GetError(),  ##__VA_ARGS__)
#define PRINT_SDL_ERROR(msg, ...) PRINT_ERROR("[SDL Error] %s\n" #msg, (char *) SDL_GetError(),  ##__VA_ARGS__)

That now give results such as

[ERROR] [TTF Error] Couldn't open ./../resources/fonts/IBMPlexSans-Medium.ttf2 "Opening font @ '`�$��U' failed" @-> /home/alxhoff/git/GitHub/FreeRTOS-Emulator/lib/Gfx/TUM_Draw.c:628, vInitDrawing [ERROR] Failed to intialize drawing @-> /home/alxhoff/git/GitHub/FreeRTOS-Emulator/src/main.c:579, main

The d-lux in error messages

PhilippvK commented 4 years ago

I really like it. Premium.