mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Handle Exceptions in main & Pythoninit (#601)
This commit is contained in:
parent
7e295a715f
commit
c4d0edd9c2
@ -19,6 +19,11 @@ PythonInit::PythonInit()
|
|||||||
// init Python
|
// init Python
|
||||||
Debug(Logger::getInstance("DAEMON"), "Initializing Python interpreter");
|
Debug(Logger::getInstance("DAEMON"), "Initializing Python interpreter");
|
||||||
Py_InitializeEx(0);
|
Py_InitializeEx(0);
|
||||||
|
if ( !Py_IsInitialized() )
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Initializing Python failed!");
|
||||||
|
}
|
||||||
|
|
||||||
PyEval_InitThreads(); // Create the GIL
|
PyEval_InitThreads(); // Create the GIL
|
||||||
mainThreadState = PyEval_SaveThread();
|
mainThreadState = PyEval_SaveThread();
|
||||||
}
|
}
|
||||||
|
@ -334,26 +334,32 @@ int main(int argc, char** argv)
|
|||||||
rootPath = rDir.absolutePath();
|
rootPath = rDir.absolutePath();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// create /.hyperion folder for default path, check if the directory is read/writeable
|
|
||||||
// NOTE: No further checks inside Hyperion. FileUtils::writeFile() will resolve permission errors and others that occur during runtime
|
|
||||||
QDir mDir(rootPath);
|
|
||||||
QFileInfo mFi(rootPath);
|
|
||||||
if(!mDir.mkpath(rootPath) || !mFi.isWritable() || !mDir.isReadable())
|
|
||||||
throw std::runtime_error("The specified root path can't be created or isn't read/writeable. Please setup the permissions correctly!");
|
|
||||||
|
|
||||||
HyperionDaemon* hyperiond = nullptr;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
hyperiond = new HyperionDaemon(rootPath, qApp, bool(logLevelCheck));
|
|
||||||
}
|
|
||||||
catch (std::exception& e)
|
|
||||||
{
|
|
||||||
Error(log, "Hyperion Daemon aborted:\n %s", e.what());
|
|
||||||
}
|
|
||||||
|
|
||||||
int rc = 1;
|
int rc = 1;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// create /.hyperion folder for default path, check if the directory is read/writeable
|
||||||
|
// NOTE: No further checks inside Hyperion. FileUtils::writeFile() will resolve permission errors and others that occur during runtime
|
||||||
|
QDir mDir(rootPath);
|
||||||
|
QFileInfo mFi(rootPath);
|
||||||
|
if(!mDir.mkpath(rootPath) || !mFi.isWritable() || !mDir.isReadable())
|
||||||
|
{
|
||||||
|
throw std::runtime_error("The specified root path can't be created or isn't read/writeable. Please setup the permissions correctly!");
|
||||||
|
}
|
||||||
|
|
||||||
|
HyperionDaemon* hyperiond = nullptr;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
hyperiond = new HyperionDaemon(rootPath, qApp, bool(logLevelCheck));
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
Error(log, "Hyperion Daemon aborted: %s", e.what());
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
// run the application
|
// run the application
|
||||||
if (isGuiApp)
|
if (isGuiApp)
|
||||||
{
|
{
|
||||||
@ -368,15 +374,14 @@ int main(int argc, char** argv)
|
|||||||
rc = app->exec();
|
rc = app->exec();
|
||||||
}
|
}
|
||||||
Info(log, "Application closed with code %d", rc);
|
Info(log, "Application closed with code %d", rc);
|
||||||
|
delete hyperiond;
|
||||||
}
|
}
|
||||||
catch (std::exception& e)
|
catch (std::exception& e)
|
||||||
{
|
{
|
||||||
Error(log, "Hyperion aborted:\n %s", e.what());
|
Error(log, "Hyperion aborted: %s", e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete components
|
// delete components
|
||||||
delete hyperiond;
|
|
||||||
Logger::deleteInstance();
|
Logger::deleteInstance();
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user