mirror of
https://github.com/johndoe6345789/SDL3CPlusPlus.git
synced 2026-04-24 13:44:58 +00:00
fix: Update error handling in ServiceBasedApp and main to fallback to console logging when logger is unavailable
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
#include "service_based_app.hpp"
|
||||
#include "logging/logger.hpp"
|
||||
#include "events/event_bus.hpp"
|
||||
#include "services/interfaces/i_window_service.hpp"
|
||||
#include "services/interfaces/i_graphics_service.hpp"
|
||||
@@ -50,7 +49,12 @@ ServiceBasedApp::ServiceBasedApp(const std::filesystem::path& scriptPath)
|
||||
|
||||
logger_->Info("ServiceBasedApp::ServiceBasedApp: constructor completed");
|
||||
} catch (const std::exception& e) {
|
||||
logging::Logger::GetInstance().Error("ServiceBasedApp::ServiceBasedApp: Failed to initialize ServiceBasedApp: " + std::string(e.what()));
|
||||
if (logger_) {
|
||||
logger_->Error("ServiceBasedApp::ServiceBasedApp: Failed to initialize ServiceBasedApp: " + std::string(e.what()));
|
||||
} else {
|
||||
// Fallback to console if logger not available
|
||||
std::cerr << "ServiceBasedApp::ServiceBasedApp: Failed to initialize ServiceBasedApp: " << e.what() << std::endl;
|
||||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,11 +332,12 @@ int main(int argc, char** argv) {
|
||||
throw std::runtime_error("Unable to determine platform config directory");
|
||||
}
|
||||
}
|
||||
sdl3cpp::app::ServiceBasedApp app(options.runtimeConfig.scriptPath);
|
||||
app.Run();
|
||||
} catch (const std::runtime_error& e) {
|
||||
std::string errorMsg = e.what();
|
||||
sdl3cpp::logging::Logger::GetInstance().Error("Runtime error: " + errorMsg);
|
||||
// For early errors before app is created, we can't use service logger
|
||||
// Fall back to console output
|
||||
std::cerr << "Runtime error: " << errorMsg << std::endl;
|
||||
|
||||
// Check if this is a timeout/hang error - show simpler message for these
|
||||
bool isTimeoutError = errorMsg.find("timeout") != std::string::npos ||
|
||||
@@ -362,7 +363,8 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
} catch (const std::exception& e) {
|
||||
sdl3cpp::logging::Logger::GetInstance().Error("Exception: " + std::string(e.what()));
|
||||
// For early errors before app is created, we can't use service logger
|
||||
std::cerr << "Exception: " << e.what() << std::endl;
|
||||
SDL_ShowSimpleMessageBox(
|
||||
SDL_MESSAGEBOX_ERROR,
|
||||
"Application Error",
|
||||
|
||||
Reference in New Issue
Block a user