libcalamares: catch Python errors in more places
- (syntax) errors in the pre-script or the module's script should not trigger a fatal error in Calamares (i.e. terminate called because of uncaught Python exception). - Log more clearly where the error is being caught.
This commit is contained in:
parent
e5c2066d28
commit
8bd2d684b9
@ -158,9 +158,34 @@ Job::exec()
|
|||||||
|
|
||||||
if ( s_preScript )
|
if ( s_preScript )
|
||||||
{
|
{
|
||||||
py::exec( s_preScript );
|
try
|
||||||
|
{
|
||||||
|
py::exec( s_preScript );
|
||||||
|
}
|
||||||
|
catch ( const py::error_already_set& e )
|
||||||
|
{
|
||||||
|
cError() << "Error in pre-script:" << e.what();
|
||||||
|
return JobResult::internalError(
|
||||||
|
tr( "Bad internal script" ),
|
||||||
|
tr( "Internal script for python job %1 raised an exception." ).arg( prettyName() ),
|
||||||
|
JobResult::PythonUncaughtException );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
py::eval_file( scriptFI.absoluteFilePath().toUtf8().constData(), scope );
|
||||||
|
}
|
||||||
|
catch ( const py::error_already_set& e )
|
||||||
|
{
|
||||||
|
cError() << "Error while loading:" << e.what();
|
||||||
|
return JobResult::internalError(
|
||||||
|
tr( "Bad main script file" ),
|
||||||
|
tr( "Main script file %1 for python job %2 could not be loaded because it raised an exception." )
|
||||||
|
.arg( scriptFI.absoluteFilePath() )
|
||||||
|
.arg( prettyName() ),
|
||||||
|
JobResult::PythonUncaughtException );
|
||||||
}
|
}
|
||||||
py::eval_file( scriptFI.absoluteFilePath().toUtf8().constData(), scope );
|
|
||||||
|
|
||||||
m_d->description = getPrettyNameFromScope( scope );
|
m_d->description = getPrettyNameFromScope( scope );
|
||||||
|
|
||||||
@ -179,7 +204,7 @@ Job::exec()
|
|||||||
catch ( const py::error_already_set& e )
|
catch ( const py::error_already_set& e )
|
||||||
{
|
{
|
||||||
// This is an error in the Python code itself
|
// This is an error in the Python code itself
|
||||||
cError() << e.what();
|
cError() << "Error while running:" << e.what();
|
||||||
return JobResult::internalError( tr( "Bad main script file" ),
|
return JobResult::internalError( tr( "Bad main script file" ),
|
||||||
tr( "Main script file %1 for python job %2 raised an exception." )
|
tr( "Main script file %1 for python job %2 raised an exception." )
|
||||||
.arg( scriptFI.absoluteFilePath() )
|
.arg( scriptFI.absoluteFilePath() )
|
||||||
@ -196,7 +221,7 @@ Job::exec()
|
|||||||
}
|
}
|
||||||
catch ( const py::cast_error& e )
|
catch ( const py::cast_error& e )
|
||||||
{
|
{
|
||||||
cError() << e.what();
|
cError() << "Error in type of run() or its results:" << e.what();
|
||||||
return JobResult::error( tr( "Bad main script file" ),
|
return JobResult::error( tr( "Bad main script file" ),
|
||||||
tr( "Main script file %1 for python job %2 returned invalid results." )
|
tr( "Main script file %1 for python job %2 returned invalid results." )
|
||||||
.arg( scriptFI.absoluteFilePath() )
|
.arg( scriptFI.absoluteFilePath() )
|
||||||
@ -204,7 +229,7 @@ Job::exec()
|
|||||||
}
|
}
|
||||||
catch ( const py::error_already_set& e )
|
catch ( const py::error_already_set& e )
|
||||||
{
|
{
|
||||||
cError() << e.what();
|
cError() << "Error in return type of run():" << e.what();
|
||||||
return JobResult::error( tr( "Bad main script file" ),
|
return JobResult::error( tr( "Bad main script file" ),
|
||||||
tr( "Main script file %1 for python job %2 returned invalid results." )
|
tr( "Main script file %1 for python job %2 returned invalid results." )
|
||||||
.arg( scriptFI.absoluteFilePath() )
|
.arg( scriptFI.absoluteFilePath() )
|
||||||
|
Loading…
Reference in New Issue
Block a user