From ff65a191c1ba2beb256caabff8b8f315a3293fbd Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sun, 17 May 2026 21:05:59 +0200 Subject: [PATCH] logLoadError sense [[noreturn]]: throw queda al call site --- source/core/resources/resource_cache.cpp | 49 +++++++++++++++--------- source/core/resources/resource_cache.hpp | 2 +- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/source/core/resources/resource_cache.cpp b/source/core/resources/resource_cache.cpp index 8539532..c245b93 100644 --- a/source/core/resources/resource_cache.cpp +++ b/source/core/resources/resource_cache.cpp @@ -244,14 +244,13 @@ namespace Resource { return rooms_; } - // Helper para lanzar errores de carga con formato consistente - [[noreturn]] void Cache::throwLoadError(const std::string& asset_type, const std::string& file_path, const std::exception& e) { + // Helper para registrar errores de carga con formato consistente. + // El rethrow es responsabilitat del catch que crida la funció. + void Cache::logLoadError(const std::string& asset_type, const std::string& file_path, const std::exception& e) { std::cerr << "\n[ ERROR ] Failed to load " << asset_type << ": " << getFileName(file_path) << '\n'; std::cerr << "[ ERROR ] Path: " << file_path << '\n'; std::cerr << "[ ERROR ] Reason: " << e.what() << '\n'; std::cerr << "[ ERROR ] Check config/assets.yaml configuration\n"; - // cppcheck-suppress rethrowNoCurrentException -- helper [[noreturn]] invocado desde dentro de un catch; cppcheck no puede ver que el rethrow es válido a través de la llamada. - throw; } // Carga los sonidos @@ -284,7 +283,8 @@ namespace Resource { printWithDots("Sound : ", name, "[ LOADED ]"); updateLoadingProgress(); } catch (const std::exception& e) { - throwLoadError("SOUND", l, e); + logLoadError("SOUND", l, e); + throw; } } } @@ -319,7 +319,8 @@ namespace Resource { printWithDots("Music : ", name, "[ LOADED ]"); updateLoadingProgress(1); } catch (const std::exception& e) { - throwLoadError("MUSIC", l, e); + logLoadError("MUSIC", l, e); + throw; } } } @@ -337,7 +338,8 @@ namespace Resource { surfaces_.back().surface->setTransparentColor(0); updateLoadingProgress(); } catch (const std::exception& e) { - throwLoadError("BITMAP", l, e); + logLoadError("BITMAP", l, e); + throw; } } @@ -360,7 +362,8 @@ namespace Resource { palettes_.emplace_back(ResourcePalette{.name = name, .palette = readPalFile(l)}); updateLoadingProgress(); } catch (const std::exception& e) { - throwLoadError("PALETTE", l, e); + logLoadError("PALETTE", l, e); + throw; } } } @@ -377,7 +380,8 @@ namespace Resource { text_files_.emplace_back(TextFileResource{.name = name, .text_file = Text::loadTextFile(l)}); updateLoadingProgress(); } catch (const std::exception& e) { - throwLoadError("FONT", l, e); + logLoadError("FONT", l, e); + throw; } } } @@ -403,7 +407,8 @@ namespace Resource { printWithDots("Animation : ", name, "[ LOADED ]"); updateLoadingProgress(); } catch (const std::exception& e) { - throwLoadError("ANIMATION", l, e); + logLoadError("ANIMATION", l, e); + throw; } } } @@ -421,7 +426,8 @@ namespace Resource { printWithDots("Room : ", name, "[ LOADED ]"); updateLoadingProgress(); } catch (const std::exception& e) { - throwLoadError("ROOM", l, e); + logLoadError("ROOM", l, e); + throw; } } } @@ -601,7 +607,8 @@ namespace Resource { it->sound = sound; std::cout << "[lazy] Sound loaded: " << name << '\n'; } catch (const std::exception& e) { - throwLoadError("SOUND", path, e); + logLoadError("SOUND", path, e); + throw; } } @@ -618,7 +625,8 @@ namespace Resource { it->music = music; std::cout << "[lazy] Music loaded: " << name << '\n'; } catch (const std::exception& e) { - throwLoadError("MUSIC", path, e); + logLoadError("MUSIC", path, e); + throw; } } @@ -638,7 +646,8 @@ namespace Resource { } std::cout << "[lazy] Surface loaded: " << name << '\n'; } catch (const std::exception& e) { - throwLoadError("BITMAP", path, e); + logLoadError("BITMAP", path, e); + throw; } } @@ -651,7 +660,8 @@ namespace Resource { it->loaded = true; std::cout << "[lazy] Palette loaded: " << name << '\n'; } catch (const std::exception& e) { - throwLoadError("PALETTE", path, e); + logLoadError("PALETTE", path, e); + throw; } } @@ -663,7 +673,8 @@ namespace Resource { it->text_file = Text::loadTextFile(path); std::cout << "[lazy] TextFile loaded: " << name << '\n'; } catch (const std::exception& e) { - throwLoadError("FONT", path, e); + logLoadError("FONT", path, e); + throw; } } @@ -677,7 +688,8 @@ namespace Resource { it->yaml_data = bytes; std::cout << "[lazy] Animation loaded: " << name << '\n'; } catch (const std::exception& e) { - throwLoadError("ANIMATION", path, e); + logLoadError("ANIMATION", path, e); + throw; } } @@ -689,7 +701,8 @@ namespace Resource { it->room = std::make_shared(Room::loadYAML(path)); std::cout << "[lazy] Room loaded: " << name << '\n'; } catch (const std::exception& e) { - throwLoadError("ROOM", path, e); + logLoadError("ROOM", path, e); + throw; } } diff --git a/source/core/resources/resource_cache.hpp b/source/core/resources/resource_cache.hpp index 1c21a43..1c63dde 100644 --- a/source/core/resources/resource_cache.hpp +++ b/source/core/resources/resource_cache.hpp @@ -88,7 +88,7 @@ namespace Resource { void updateLoadingProgress(int steps = 5); // Helper para mensajes de error de carga - [[noreturn]] static void throwLoadError(const std::string& asset_type, const std::string& file_path, const std::exception& e); + static void logLoadError(const std::string& asset_type, const std::string& file_path, const std::exception& e); // Constructor y destructor explicit Cache(LoadingMode mode);