fix: throw; al call site, no a l'helper

This commit is contained in:
2026-05-14 20:11:37 +02:00
parent f3566821a6
commit 2c55dd8eb4
2 changed files with 18 additions and 11 deletions

View File

@@ -362,13 +362,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) { // NOLINT(readability-convert-member-functions-to-static)
// 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) { // NOLINT(readability-convert-member-functions-to-static)
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";
throw;
}
// Lista fija de text objects. Compartida entre createText() y createOneText(i).
@@ -415,7 +415,8 @@ namespace Resource {
printWithDots("Sound : ", name, "[ LOADED ]");
updateLoadingProgress();
} catch (const std::exception& e) {
throwLoadError("SOUND", l, e);
logLoadError("SOUND", l, e);
throw;
}
}
@@ -442,7 +443,8 @@ namespace Resource {
printWithDots("Music : ", name, "[ LOADED ]");
updateLoadingProgress();
} catch (const std::exception& e) {
throwLoadError("MUSIC", l, e);
logLoadError("MUSIC", l, e);
throw;
}
}
@@ -456,7 +458,8 @@ namespace Resource {
surfaces_.back().surface->setTransparentColor(0);
updateLoadingProgress();
} catch (const std::exception& e) {
throwLoadError("BITMAP", l, e);
logLoadError("BITMAP", l, e);
throw;
}
}
@@ -480,7 +483,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;
}
}
@@ -493,7 +497,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;
}
}
@@ -513,7 +518,8 @@ namespace Resource {
printWithDots("Animation : ", name, "[ LOADED ]");
updateLoadingProgress();
} catch (const std::exception& e) {
throwLoadError("ANIMATION", l, e);
logLoadError("ANIMATION", l, e);
throw;
}
}
@@ -527,7 +533,8 @@ namespace Resource {
printWithDots("Room : ", name, "[ LOADED ]");
updateLoadingProgress();
} catch (const std::exception& e) {
throwLoadError("ROOM", l, e);
logLoadError("ROOM", l, e);
throw;
}
}

View File

@@ -100,7 +100,7 @@ namespace Resource {
void setCurrentLoading(const std::string& name); // Desa el nom del recurs en curs
// 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
Cache();