diff --git a/src/nvhttp.cpp b/src/nvhttp.cpp index 8a3da714..716c16f1 100644 --- a/src/nvhttp.cpp +++ b/src/nvhttp.cpp @@ -40,6 +40,8 @@ using namespace std::literals; namespace nvhttp { + static constexpr std::string_view EMPTY_PROPERTY_TREE_ERROR_MSG = "Property tree is empty. Probably, control flow got interrupted by an unexpected C++ exception. This is a bug in Sunshine. Moonlight-qt will report Malformed XML (missing root element)."sv; + namespace fs = std::filesystem; namespace pt = boost::property_tree; @@ -816,6 +818,10 @@ namespace nvhttp { auto g = util::fail_guard([&]() { std::ostringstream data; + if (tree.empty()) { + BOOST_LOG(error) << EMPTY_PROPERTY_TREE_ERROR_MSG; + } + pt::write_xml(data, tree); response->write(data.str()); response->close_connection_after_response = true; @@ -922,6 +928,10 @@ namespace nvhttp { auto g = util::fail_guard([&]() { std::ostringstream data; + if (tree.empty()) { + BOOST_LOG(error) << EMPTY_PROPERTY_TREE_ERROR_MSG; + } + pt::write_xml(data, tree); response->write(data.str()); response->close_connection_after_response = true; diff --git a/src/process.cpp b/src/process.cpp index fb123470..1bf41c59 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -97,11 +98,17 @@ namespace proc { boost::filesystem::path find_working_directory(const std::string &cmd, boost::process::v1::environment &env) { // Parse the raw command string into parts to get the actual command portion + std::vector parts; + try { #ifdef _WIN32 - auto parts = boost::program_options::split_winmain(cmd); + parts = boost::program_options::split_winmain(cmd); #else - auto parts = boost::program_options::split_unix(cmd); + parts = boost::program_options::split_unix(cmd); #endif + } catch (boost::escaped_list_error &err) { + BOOST_LOG(error) << "Boost failed to parse command ["sv << cmd << "] because " << err.what(); + return boost::filesystem::path(); + } if (parts.empty()) { BOOST_LOG(error) << "Unable to parse command: "sv << cmd; return boost::filesystem::path(); @@ -217,10 +224,14 @@ namespace proc { } } - child.wait(); + child.wait(ec); + if (ec) { + BOOST_LOG(error) << '[' << cmd.do_cmd << "] wait failed with error code ["sv << ec << ']'; + return -1; + } auto ret = child.exit_code(); - if (ret != 0 && ec != std::errc::permission_denied) { - BOOST_LOG(error) << '[' << cmd.do_cmd << "] failed with code ["sv << ret << ']'; + if (ret != 0) { + BOOST_LOG(error) << '[' << cmd.do_cmd << "] exited with code ["sv << ret << ']'; return -1; } }