logLoadError sense [[noreturn]]: throw queda al call site
This commit is contained in:
@@ -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::Data>(Room::loadYAML(path));
|
||||
std::cout << "[lazy] Room loaded: " << name << '\n';
|
||||
} catch (const std::exception& e) {
|
||||
throwLoadError("ROOM", path, e);
|
||||
logLoadError("ROOM", path, e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user