From b4d43518256502d923fa947eb76e093c13f5ab4c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 Nov 2017 08:22:47 -0500 Subject: [PATCH 01/10] [libcalamares] Better Python traceback handling: - log the whole error message as plain text - convert to HTML only for the ui --- src/libcalamares/PythonHelper.cpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/libcalamares/PythonHelper.cpp b/src/libcalamares/PythonHelper.cpp index 14a63f4d3..76f838a49 100644 --- a/src/libcalamares/PythonHelper.cpp +++ b/src/libcalamares/PythonHelper.cpp @@ -257,9 +257,9 @@ Helper::handleLastError() bp::str pystr( h_type ); bp::extract< std::string > extracted( pystr ); if ( extracted.check() ) - typeMsg = QString::fromStdString( extracted() ).toHtmlEscaped(); + typeMsg = QString::fromStdString( extracted() ).trimmed(); - if ( typeMsg.trimmed().isEmpty() ) + if ( typeMsg.isEmpty() ) typeMsg = tr( "Unknown exception type" ); } @@ -270,9 +270,9 @@ Helper::handleLastError() bp::str pystr( h_val ); bp::extract< std::string > extracted( pystr ); if ( extracted.check() ) - valMsg = QString::fromStdString( extracted() ).toHtmlEscaped(); + valMsg = QString::fromStdString( extracted() ).trimmed(); - if ( valMsg.trimmed().isEmpty() ) + if ( valMsg.isEmpty() ) valMsg = tr( "unparseable Python error" ); } @@ -286,9 +286,9 @@ Helper::handleLastError() bp::object pystr( bp::str( "\n" ).join( tb_list ) ); bp::extract< std::string > extracted( pystr ); if ( extracted.check() ) - tbMsg = QString::fromStdString( extracted() ).toHtmlEscaped(); + tbMsg = QString::fromStdString( extracted() ).trimmed(); - if ( tbMsg.trimmed().isEmpty() ) + if ( tbMsg.isEmpty() ) tbMsg = tr( "unparseable Python traceback" ); } @@ -298,17 +298,26 @@ Helper::handleLastError() QStringList msgList; + Logger::CDebug debug; + debug.noquote() << "Python Error:\n"; + if ( !typeMsg.isEmpty() ) - msgList.append( QString( "%1" ).arg( typeMsg ) ); + { + debug << typeMsg << '\n'; + msgList.append( QString( "%1" ).arg( typeMsg.toHtmlEscaped() ) ); + } if ( !valMsg.isEmpty() ) - msgList.append( valMsg ); + { + debug << valMsg << '\n'; + msgList.append( valMsg.toHtmlEscaped() ); + } if ( !tbMsg.isEmpty() ) { msgList.append( "Traceback:" ); - msgList.append( QString( "
%1
" ).arg( tbMsg ) ); - cDebug() << "tbMsg" << tbMsg; + msgList.append( QString( "
%1
" ).arg( tbMsg.toHtmlEscaped() ) ); + debug << tbMsg << '\n'; } // Return a string made of the msgList items, wrapped in
tags From 1f3f6111f716f31a97246d8bb1af7f1ebfffa18b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 Nov 2017 08:40:12 -0500 Subject: [PATCH 02/10] [libcalamares] Log output from failed commands --- src/libcalamares/utils/CalamaresUtilsSystem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.cpp b/src/libcalamares/utils/CalamaresUtilsSystem.cpp index 35f394364..4103140f9 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.cpp +++ b/src/libcalamares/utils/CalamaresUtilsSystem.cpp @@ -209,8 +209,8 @@ System::targetEnvOutput( const QStringList& args, cLog() << "Finished. Exit code:" << r; if ( r != 0 ) { - cLog() << "Target cmd" << args; - cLog() << "Target out" << output; + cLog() << "Target cmd:" << args; + cLog().noquote() << "Target output:\n" << output; } return r; } From f5aec1ad8a8e6f62dd87b602ee1c6541ede42a1c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 Nov 2017 08:53:40 -0500 Subject: [PATCH 03/10] [libcalamares] Add output to CalledProcessError - Refactor, internal _handle_check_target_env_call_error doesn't need to be in header or visible. - Add optional output (of the command) to the Python exception. --- src/libcalamares/PythonJobApi.cpp | 35 ++++++++++++++++--------------- src/libcalamares/PythonJobApi.h | 2 -- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/libcalamares/PythonJobApi.cpp b/src/libcalamares/PythonJobApi.cpp index 595f53a76..c9a3873bd 100644 --- a/src/libcalamares/PythonJobApi.cpp +++ b/src/libcalamares/PythonJobApi.cpp @@ -36,6 +36,24 @@ namespace bp = boost::python; +static int +_handle_check_target_env_call_error( int ec, const QString& cmd, const QString& output = QString() ) +{ + if ( !ec ) + return ec; + + QString raise = QString( "import subprocess\n" + "e = subprocess.CalledProcessError(%1,\"%2\")\n" ) + .arg( ec ) + .arg( cmd ); + if ( !output.isEmpty() ) + raise.append( QStringLiteral("e.output = \"\"\"%1\"\"\"\n").arg( output ) ); + raise.append("raise e"); + bp::exec( raise.toStdString().c_str() ); + bp::throw_error_already_set(); + return ec; +} + namespace CalamaresPython { @@ -156,23 +174,6 @@ check_target_env_output( const bp::list& args, return output.toStdString(); } - -int -_handle_check_target_env_call_error( int ec, const QString& cmd ) -{ - if ( !ec ) - return ec; - - QString raise = QString( "import subprocess\n" - "raise subprocess.CalledProcessError(%1,\"%2\")" ) - .arg( ec ) - .arg( cmd ); - bp::exec( raise.toStdString().c_str() ); - bp::throw_error_already_set(); - return ec; -} - - void debug( const std::string& s ) { diff --git a/src/libcalamares/PythonJobApi.h b/src/libcalamares/PythonJobApi.h index 3d31c474e..c88101d28 100644 --- a/src/libcalamares/PythonJobApi.h +++ b/src/libcalamares/PythonJobApi.h @@ -67,8 +67,6 @@ boost::python::list gettext_languages(); void debug( const std::string& s ); -inline int _handle_check_target_env_call_error( int ec, const QString& cmd ); - class PythonJobInterface { public: From 9d3138098018a7606494cf2ab49f9cef0b0bea9e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 Nov 2017 10:27:24 -0500 Subject: [PATCH 04/10] [libcalamares] Refactor target-environment calls - Add a more general targetEnvCommand() that returns both error code and process output. - Change existing targetEnvCall() and targetEnvOutput() to use general form while discarding some data. --- .../utils/CalamaresUtilsSystem.cpp | 59 +++-------------- src/libcalamares/utils/CalamaresUtilsSystem.h | 63 +++++++++++++++---- 2 files changed, 60 insertions(+), 62 deletions(-) diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.cpp b/src/libcalamares/utils/CalamaresUtilsSystem.cpp index 4103140f9..ca981459c 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.cpp +++ b/src/libcalamares/utils/CalamaresUtilsSystem.cpp @@ -92,42 +92,14 @@ System::mount( const QString& devicePath, return QProcess::execute( program, args ); } -int -System::targetEnvCall( const QStringList& args, - const QString& workingPath, - const QString& stdInput, - int timeoutSec ) -{ - QString discard; - return targetEnvOutput( args, - discard, - workingPath, - stdInput, - timeoutSec ); -} - - -int -System::targetEnvCall( const QString& command, - const QString& workingPath, - const QString& stdInput, - int timeoutSec ) -{ - return targetEnvCall( QStringList{ command }, - workingPath, - stdInput, - timeoutSec ); -} - - -int -System::targetEnvOutput( const QStringList& args, - QString& output, - const QString& workingPath, - const QString& stdInput, - int timeoutSec ) +ProcessResult +System::targetEnvCommand( + const QStringList& args, + const QString& workingPath, + const QString& stdInput, + int timeoutSec ) { - output.clear(); + QString output; if ( !Calamares::JobQueue::instance() ) return -3; @@ -212,22 +184,7 @@ System::targetEnvOutput( const QStringList& args, cLog() << "Target cmd:" << args; cLog().noquote() << "Target output:\n" << output; } - return r; -} - - -int -System::targetEnvOutput( const QString& command, - QString& output, - const QString& workingPath, - const QString& stdInput, - int timeoutSec ) -{ - return targetEnvOutput( QStringList{ command }, - output, - workingPath, - stdInput, - timeoutSec ); + return ProcessResult(r, output); } diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.h b/src/libcalamares/utils/CalamaresUtilsSystem.h index 34ab7ecbd..a1f71fef3 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.h +++ b/src/libcalamares/utils/CalamaresUtilsSystem.h @@ -21,10 +21,18 @@ #include "DllMacro.h" #include +#include #include namespace CalamaresUtils { +class ProcessResult : public QPair< int, QString > +{ +public: + /** @brief Implicit one-argument constructor has no output, only a return code */ + ProcessResult( int r ) : QPair< int, QString >( r, QString() ) {} + ProcessResult( int r, QString s ) : QPair< int, QString >( r, s ) {} +} ; /** * @brief The System class is a singleton with utility functions that perform @@ -61,42 +69,75 @@ public: const QString& filesystemName = QString(), const QString& options = QString() ); + /** * Runs the specified command in the chroot of the target system. - * @param args the call with arguments, as a string list. + * @param args the command with arguments, as a string list. * @param workingPath the current working directory for the QProcess * call (optional). * @param stdInput the input string to send to the running process as * standard input (optional). * @param timeoutSec the timeout after which the process will be * killed (optional, default is 0 i.e. no timeout). - * @returns the program's exit code, or: + * + * @returns the program's exit code and its output (if any). Special + * exit codes (which will never have any output) are: * -1 = QProcess crash * -2 = QProcess cannot start * -3 = bad arguments * -4 = QProcess timeout */ - DLLEXPORT int targetEnvCall( const QStringList& args, + DLLEXPORT ProcessResult targetEnvCommand( + const QStringList &args, + const QString& workingPath = QString(), + const QString& stdInput = QString(), + int timeoutSec = 0 ); + + /** @brief Convenience wrapper for targetEnvCommand() which returns only the exit code */ + inline int targetEnvCall( const QStringList& args, const QString& workingPath = QString(), const QString& stdInput = QString(), - int timeoutSec = 0 ); + int timeoutSec = 0 ) + { + return targetEnvCommand( args, workingPath, stdInput, timeoutSec ).first; + } - DLLEXPORT int targetEnvCall( const QString& command, + /** @brief Convenience wrapper for targetEnvCommand() which returns only the exit code */ + inline int targetEnvCall( const QString& command, const QString& workingPath = QString(), const QString& stdInput = QString(), - int timeoutSec = 0 ); + int timeoutSec = 0 ) + { + return targetEnvCall( QStringList{ command }, workingPath, stdInput, timeoutSec ); + } - DLLEXPORT int targetEnvOutput( const QStringList& args, + /** @brief Convenience wrapper for targetEnvCommand() which returns only the exit code + * + * Places the called program's output in the @p output string. + */ + int targetEnvOutput( const QStringList& args, QString& output, const QString& workingPath = QString(), const QString& stdInput = QString(), - int timeoutSec = 0 ); - - DLLEXPORT int targetEnvOutput( const QString& command, + int timeoutSec = 0 ) + { + auto r = targetEnvCommand( args, workingPath, stdInput, timeoutSec ); + output = r.second; + return r.first; + } + + /** @brief Convenience wrapper for targetEnvCommand() which returns only the exit code + * + * Places the called program's output in the @p output string. + */ + inline int targetEnvOutput( const QString& command, QString& output, const QString& workingPath = QString(), const QString& stdInput = QString(), - int timeoutSec = 0 ); + int timeoutSec = 0 ) + { + return targetEnvOutput( QStringList{ command }, output, workingPath, stdInput, timeoutSec ); + } /** * @brief getTotalMemoryB returns the total main memory, in bytes. From 6693d911527180c64a11a895dd0a9a50c91aa951 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 Nov 2017 10:42:00 -0500 Subject: [PATCH 05/10] [libcalamares] Refactor bp:list -> QStringList --- src/libcalamares/PythonJobApi.cpp | 37 +++++++++++++------------------ 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/src/libcalamares/PythonJobApi.cpp b/src/libcalamares/PythonJobApi.cpp index c9a3873bd..4cbb8c260 100644 --- a/src/libcalamares/PythonJobApi.cpp +++ b/src/libcalamares/PythonJobApi.cpp @@ -71,6 +71,18 @@ mount( const std::string& device_path, } +static inline QStringList +_bp_list_to_qstringlist( const bp::list& args ) +{ + QStringList list; + for ( int i = 0; i < bp::len( args ); ++i ) + { + list.append( QString::fromStdString( + bp::extract< std::string >( args[ i ] ) ) ); + } + return list; +} + int target_env_call( const std::string& command, const std::string& stdin, @@ -89,15 +101,8 @@ target_env_call( const bp::list& args, const std::string& stdin, int timeout ) { - QStringList list; - for ( int i = 0; i < bp::len( args ); ++i ) - { - list.append( QString::fromStdString( - bp::extract< std::string >( args[ i ] ) ) ); - } - return CalamaresUtils::System::instance()-> - targetEnvCall( list, + targetEnvCall( _bp_list_to_qstringlist( args ), QString(), QString::fromStdString( stdin ), timeout ); @@ -123,13 +128,7 @@ check_target_env_call( const bp::list& args, if ( !ec ) return ec; - QStringList failedCmdList; - for ( int i = 0; i < bp::len( args ); ++i ) - { - failedCmdList.append( QString::fromStdString( - bp::extract< std::string >( args[ i ] ) ) ); - } - + QStringList failedCmdList = _bp_list_to_qstringlist( args ); return _handle_check_target_env_call_error( ec, failedCmdList.join( ' ' ) ); } @@ -157,13 +156,7 @@ check_target_env_output( const bp::list& args, int timeout ) { QString output; - QStringList list; - for ( int i = 0; i < bp::len( args ); ++i ) - { - list.append( QString::fromStdString( - bp::extract< std::string >( args[ i ] ) ) ); - } - + QStringList list = _bp_list_to_qstringlist( args ); int ec = CalamaresUtils::System::instance()-> targetEnvOutput( list, output, From a0a8ab0048fbc753cc3fe3df5346d881971b0daf Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 Nov 2017 10:55:53 -0500 Subject: [PATCH 06/10] [libcalamares] Refactor Python target_env calls This is why the whole refactoring started: to get the process output and exit code in one spot so we can attach the process output to the (Python exception) CalledProcessError in all the code paths, not just those that are explicitly looking for output. --- src/libcalamares/PythonJobApi.cpp | 72 +++++++++++++++---------------- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/src/libcalamares/PythonJobApi.cpp b/src/libcalamares/PythonJobApi.cpp index 4cbb8c260..40d178cf9 100644 --- a/src/libcalamares/PythonJobApi.cpp +++ b/src/libcalamares/PythonJobApi.cpp @@ -37,21 +37,21 @@ namespace bp = boost::python; static int -_handle_check_target_env_call_error( int ec, const QString& cmd, const QString& output = QString() ) +_handle_check_target_env_call_error( const CalamaresUtils::ProcessResult& ec, const QString& cmd ) { - if ( !ec ) - return ec; + if ( !ec.first ) + return ec.first; QString raise = QString( "import subprocess\n" "e = subprocess.CalledProcessError(%1,\"%2\")\n" ) - .arg( ec ) + .arg( ec.first ) .arg( cmd ); - if ( !output.isEmpty() ) - raise.append( QStringLiteral("e.output = \"\"\"%1\"\"\"\n").arg( output ) ); + if ( !ec.second.isEmpty() ) + raise.append( QStringLiteral("e.output = \"\"\"%1\"\"\"\n").arg( ec.second ) ); raise.append("raise e"); bp::exec( raise.toStdString().c_str() ); bp::throw_error_already_set(); - return ec; + return ec.first; } namespace CalamaresPython @@ -83,29 +83,36 @@ _bp_list_to_qstringlist( const bp::list& args ) return list; } -int -target_env_call( const std::string& command, - const std::string& stdin, - int timeout ) +static inline CalamaresUtils::ProcessResult +_target_env_command( + const QStringList& args, + const std::string& stdin, + int timeout ) { return CalamaresUtils::System::instance()-> - targetEnvCall( QString::fromStdString( command ), + targetEnvCommand( args, QString(), QString::fromStdString( stdin ), timeout ); } +int +target_env_call( const std::string& command, + const std::string& stdin, + int timeout ) +{ + return _target_env_command( + QStringList{ QString::fromStdString( command ) }, stdin, timeout ).first; +} + int target_env_call( const bp::list& args, const std::string& stdin, int timeout ) { - return CalamaresUtils::System::instance()-> - targetEnvCall( _bp_list_to_qstringlist( args ), - QString(), - QString::fromStdString( stdin ), - timeout ); + return _target_env_command( + _bp_list_to_qstringlist( args ), stdin, timeout ).first; } @@ -114,7 +121,8 @@ check_target_env_call( const std::string& command, const std::string& stdin, int timeout ) { - int ec = target_env_call( command, stdin, timeout ); + auto ec = _target_env_command( + QStringList{ QString::fromStdString( command ) }, stdin, timeout ); return _handle_check_target_env_call_error( ec, QString::fromStdString( command ) ); } @@ -124,9 +132,9 @@ check_target_env_call( const bp::list& args, const std::string& stdin, int timeout ) { - int ec = target_env_call( args, stdin, timeout ); - if ( !ec ) - return ec; + auto ec = _target_env_command( _bp_list_to_qstringlist( args ), stdin, timeout ); + if ( !ec.first ) + return ec.first; QStringList failedCmdList = _bp_list_to_qstringlist( args ); return _handle_check_target_env_call_error( ec, failedCmdList.join( ' ' ) ); @@ -138,15 +146,10 @@ check_target_env_output( const std::string& command, const std::string& stdin, int timeout ) { - QString output; - int ec = CalamaresUtils::System::instance()-> - targetEnvOutput( QString::fromStdString( command ), - output, - QString(), - QString::fromStdString( stdin ), - timeout ); + auto ec = _target_env_command( + QStringList{ QString::fromStdString( command ) }, stdin, timeout ); _handle_check_target_env_call_error( ec, QString::fromStdString( command ) ); - return output.toStdString(); + return ec.second.toStdString(); } @@ -155,16 +158,11 @@ check_target_env_output( const bp::list& args, const std::string& stdin, int timeout ) { - QString output; QStringList list = _bp_list_to_qstringlist( args ); - int ec = CalamaresUtils::System::instance()-> - targetEnvOutput( list, - output, - QString(), - QString::fromStdString( stdin ), - timeout ); + auto ec = _target_env_command( + list, stdin, timeout ); _handle_check_target_env_call_error( ec, list.join( ' ' ) ); - return output.toStdString(); + return ec.second.toStdString(); } void From 1e27c6438ad73d50dedd60177531fc31fd7bb4fc Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 Nov 2017 11:21:42 -0500 Subject: [PATCH 07/10] [libcalamares] Special-case CalledProcessError --- src/libcalamares/PythonHelper.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/libcalamares/PythonHelper.cpp b/src/libcalamares/PythonHelper.cpp index 76f838a49..33e3b00d4 100644 --- a/src/libcalamares/PythonHelper.cpp +++ b/src/libcalamares/PythonHelper.cpp @@ -274,6 +274,19 @@ Helper::handleLastError() if ( valMsg.isEmpty() ) valMsg = tr( "unparseable Python error" ); + + // Special-case: CalledProcessError has an attribute "output" with the command output, + // add that to the printed message. + if ( typeMsg.contains( "CalledProcessError" ) ) + { + bp::object exceptionObject( h_val ); + auto a = exceptionObject.attr( "output" ); + bp::str outputString( a ); + bp::extract< std::string > extractedOutput( outputString ); + + if ( extractedOutput.check() ) + valMsg.append( QString::fromStdString( extractedOutput() ) ); + } } QString tbMsg; From 9df796a3fd353e715afe86d0dfd5dc72c4c9892d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 Nov 2017 11:26:59 -0500 Subject: [PATCH 08/10] [libcalamares] Log earlier, warnings-- --- src/libcalamares/PythonHelper.cpp | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/libcalamares/PythonHelper.cpp b/src/libcalamares/PythonHelper.cpp index 33e3b00d4..27100bada 100644 --- a/src/libcalamares/PythonHelper.cpp +++ b/src/libcalamares/PythonHelper.cpp @@ -247,8 +247,11 @@ Helper::createCleanNamespace() QString Helper::handleLastError() { - PyObject* type = nullptr, *val = nullptr, *tb = nullptr; - PyErr_Fetch( &type, &val, &tb ); + PyObject* type = nullptr, *val = nullptr, *traceback_p = nullptr; + PyErr_Fetch( &type, &val, &traceback_p ); + + Logger::CDebug debug; + debug.noquote() << "Python Error:\n"; QString typeMsg; if ( type != nullptr ) @@ -261,6 +264,7 @@ Helper::handleLastError() if ( typeMsg.isEmpty() ) typeMsg = tr( "Unknown exception type" ); + debug << typeMsg << '\n'; } QString valMsg; @@ -287,14 +291,15 @@ Helper::handleLastError() if ( extractedOutput.check() ) valMsg.append( QString::fromStdString( extractedOutput() ) ); } + debug << valMsg << '\n'; } QString tbMsg; - if ( tb != nullptr ) + if ( traceback_p != nullptr ) { - bp::handle<> h_tb( tb ); - bp::object tb( bp::import( "traceback" ) ); - bp::object format_tb( tb.attr( "format_tb" ) ); + bp::handle<> h_tb( traceback_p ); + bp::object traceback_module( bp::import( "traceback" ) ); + bp::object format_tb( traceback_module.attr( "format_tb" ) ); bp::object tb_list( format_tb( h_tb ) ); bp::object pystr( bp::str( "\n" ).join( tb_list ) ); bp::extract< std::string > extracted( pystr ); @@ -303,6 +308,7 @@ Helper::handleLastError() if ( tbMsg.isEmpty() ) tbMsg = tr( "unparseable Python traceback" ); + debug << tbMsg << '\n'; } if ( typeMsg.isEmpty() && valMsg.isEmpty() && tbMsg.isEmpty() ) @@ -310,27 +316,15 @@ Helper::handleLastError() QStringList msgList; - - Logger::CDebug debug; - debug.noquote() << "Python Error:\n"; - if ( !typeMsg.isEmpty() ) - { - debug << typeMsg << '\n'; msgList.append( QString( "%1" ).arg( typeMsg.toHtmlEscaped() ) ); - } - if ( !valMsg.isEmpty() ) - { - debug << valMsg << '\n'; msgList.append( valMsg.toHtmlEscaped() ); - } if ( !tbMsg.isEmpty() ) { msgList.append( "Traceback:" ); msgList.append( QString( "
%1
" ).arg( tbMsg.toHtmlEscaped() ) ); - debug << tbMsg << '\n'; } // Return a string made of the msgList items, wrapped in
tags From cc195eb3d4dd24c8ec2b4133d2586e5d8eef89fe Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 Nov 2017 11:38:26 -0500 Subject: [PATCH 09/10] [libcalamares] Improve reporting of CalledProcessError For called processes, replace the not-very-useful type message with the command-explanation, and replace the value (previously command-explanation) by the stderr of the failed command. FIXES #865 --- src/libcalamares/PythonHelper.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/libcalamares/PythonHelper.cpp b/src/libcalamares/PythonHelper.cpp index 27100bada..11e199e0c 100644 --- a/src/libcalamares/PythonHelper.cpp +++ b/src/libcalamares/PythonHelper.cpp @@ -288,8 +288,18 @@ Helper::handleLastError() bp::str outputString( a ); bp::extract< std::string > extractedOutput( outputString ); + QString output; if ( extractedOutput.check() ) - valMsg.append( QString::fromStdString( extractedOutput() ) ); + { + output = QString::fromStdString( extractedOutput() ).trimmed(); + } + if ( !output.isEmpty() ) + { + // Replace the Type of the error by the warning string, + // and use the output of the command (e.g. its stderr) as value. + typeMsg = valMsg; + valMsg = output; + } } debug << valMsg << '\n'; } @@ -323,7 +333,7 @@ Helper::handleLastError() if ( !tbMsg.isEmpty() ) { - msgList.append( "Traceback:" ); + msgList.append( QStringLiteral( "
Traceback:" ) ); msgList.append( QString( "
%1
" ).arg( tbMsg.toHtmlEscaped() ) ); } From c2843048729126999d9bd25efe3e7a1191a5c03a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 Nov 2017 11:41:17 -0500 Subject: [PATCH 10/10] [libcalamares] Adjust copyright lines --- src/libcalamares/PythonHelper.cpp | 1 + src/libcalamares/utils/CalamaresUtilsSystem.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/libcalamares/PythonHelper.cpp b/src/libcalamares/PythonHelper.cpp index 11e199e0c..37a8a70fb 100644 --- a/src/libcalamares/PythonHelper.cpp +++ b/src/libcalamares/PythonHelper.cpp @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014, Teo Mrnjavac + * Copyright 2017, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.h b/src/libcalamares/utils/CalamaresUtilsSystem.h index a1f71fef3..be2da28ae 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.h +++ b/src/libcalamares/utils/CalamaresUtilsSystem.h @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014, Teo Mrnjavac + * Copyright 2017, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by