fix: improve error handling and logging in data generation pipeline

This commit is contained in:
Aaron Po
2026-04-07 13:36:59 -04:00
parent b8e96a6d45
commit 54c403526b
4 changed files with 183 additions and 116 deletions

View File

@@ -58,7 +58,7 @@ auto BiergartenDataGenerator::QueryCitiesWithCountries()
auto all_locations = JsonLoader::LoadLocations(locations_path.string());
spdlog::info(" Locations available: {}", all_locations.size());
const size_t sample_count = std::min<size_t>(30, all_locations.size());
const size_t sample_count = std::min<size_t>(4, all_locations.size());
std::vector<Location> sampled_locations;
sampled_locations.reserve(sample_count);
@@ -106,11 +106,27 @@ void BiergartenDataGenerator::GenerateBreweries(
spdlog::info("\n=== SAMPLE BREWERY GENERATION ===");
generatedBreweries_.clear();
size_t skipped_count = 0;
for (const auto& enriched_city : cities) {
auto brewery = generator.GenerateBrewery(enriched_city.location.city,
enriched_city.location.country,
enriched_city.region_context);
generatedBreweries_.push_back({enriched_city.location, brewery});
try {
auto brewery = generator.GenerateBrewery(enriched_city.location.city,
enriched_city.location.country,
enriched_city.region_context);
generatedBreweries_.push_back({enriched_city.location, brewery});
} catch (const std::exception& e) {
++skipped_count;
spdlog::warn(
"[Pipeline] Skipping city '{}' ({}): brewery generation failed: {}",
enriched_city.location.city, enriched_city.location.country,
e.what());
}
}
if (skipped_count > 0) {
spdlog::warn("[Pipeline] Skipped {} city/cities due to generation "
"errors",
skipped_count);
}
}

View File

@@ -126,6 +126,15 @@ int main(int argc, char* argv[]) {
return generator.Run();
} catch (const std::exception& e) {
const std::string message = e.what() ? e.what() : "";
if (message.find("LlamaGenerator: malformed brewery response") !=
std::string::npos) {
spdlog::warn("WARNING: Non-fatal LLM failure after retries: {}",
message);
return 0;
}
spdlog::error("ERROR: Application failed: {}", e.what());
return 1;
}