Show python errors in Project Manager for adding repos and downloading gems

Signed-off-by: AMZN-Phil <pconroy@amazon.com>
This commit is contained in:
AMZN-Phil
2021-11-16 14:24:02 -08:00
parent dd1d515e37
commit 808c783109
8 changed files with 55 additions and 29 deletions
@@ -33,7 +33,7 @@ namespace O3DE::ProjectManager
}
else
{
emit Done(tr("Gem download failed"));
emit Done(gemInfoResult.GetError().c_str());
}
}
@@ -92,8 +92,8 @@ namespace O3DE::ProjectManager
return;
}
bool addGemRepoResult = PythonBindingsInterface::Get()->AddGemRepo(repoUri);
if (addGemRepoResult)
AZ::Outcome<void, AZStd::string> addGemRepoResult = PythonBindingsInterface::Get()->AddGemRepo(repoUri);
if (addGemRepoResult.IsSuccess())
{
Reinit();
emit OnRefresh();
@@ -101,8 +101,8 @@ namespace O3DE::ProjectManager
else
{
QString failureMessage = tr("Failed to add gem repo: %1.").arg(repoUri);
QMessageBox::critical(this, tr("Operation failed"), failureMessage);
AZ_Error("Project Manger", false, failureMessage.toUtf8());
QMessageBox::critical(this, failureMessage, addGemRepoResult.GetError().c_str());
AZ_Error("Project Manager", false, failureMessage.toUtf8());
}
}
}
@@ -61,6 +61,7 @@ namespace Platform
namespace RedirectOutput
{
using RedirectOutputFunc = AZStd::function<void(const char*)>;
AZStd::string lastPythonError;
struct RedirectOutput
{
@@ -210,6 +211,16 @@ namespace RedirectOutput
});
SetRedirection("stderr", g_redirect_stderr_saved, g_redirect_stderr, []([[maybe_unused]] const char* msg) {
if (lastPythonError.empty())
{
lastPythonError = msg;
const int lengthOfErrorPrefix = 11;
auto errorPrefix = lastPythonError.find("ERROR:root:");
if (errorPrefix != AZStd::string::npos)
{
lastPythonError.erase(errorPrefix, lengthOfErrorPrefix);
}
}
AZ_TracePrintf("Python", msg);
});
@@ -1051,12 +1062,13 @@ namespace O3DE::ProjectManager
return result && refreshResult;
}
bool PythonBindings::AddGemRepo(const QString& repoUri)
AZ::Outcome<void, AZStd::string> PythonBindings::AddGemRepo(const QString& repoUri)
{
bool registrationResult = false;
bool result = ExecuteWithLock(
[&]
{
RedirectOutput::lastPythonError.clear();
auto pyUri = QString_To_Py_String(repoUri);
auto pythonRegistrationResult = m_register.attr("register")(
pybind11::none(), pybind11::none(), pybind11::none(), pybind11::none(), pybind11::none(), pybind11::none(), pyUri);
@@ -1065,7 +1077,12 @@ namespace O3DE::ProjectManager
registrationResult = !pythonRegistrationResult.cast<bool>();
});
return result && registrationResult;
if (!result || !registrationResult)
{
return AZ::Failure<AZStd::string>(AZStd::move(RedirectOutput::lastPythonError));
}
return AZ::Success();
}
bool PythonBindings::RemoveGemRepo(const QString& repoUri)
@@ -1225,6 +1242,7 @@ namespace O3DE::ProjectManager
auto result = ExecuteWithLockErrorHandling(
[&]
{
RedirectOutput::lastPythonError.clear();
auto downloadResult = m_download.attr("download_gem")(
QString_To_Py_String(gemName), // gem name
pybind11::none(), // destination path
@@ -1248,7 +1266,7 @@ namespace O3DE::ProjectManager
}
else if (!downloadSucceeded)
{
return AZ::Failure<AZStd::string>("Failed to download gem.");
return AZ::Failure<AZStd::string>(AZStd::move(RedirectOutput::lastPythonError));
}
return AZ::Success();
@@ -62,7 +62,7 @@ namespace O3DE::ProjectManager
// Gem Repos
AZ::Outcome<void, AZStd::string> RefreshGemRepo(const QString& repoUri) override;
bool RefreshAllGemRepos() override;
bool AddGemRepo(const QString& repoUri) override;
AZ::Outcome<void, AZStd::string> AddGemRepo(const QString& repoUri) override;
bool RemoveGemRepo(const QString& repoUri) override;
AZ::Outcome<QVector<GemRepoInfo>, AZStd::string> GetAllGemRepoInfos() override;
AZ::Outcome<QVector<GemInfo>, AZStd::string> GetAllGemRepoGemsInfos() override;
@@ -200,9 +200,9 @@ namespace O3DE::ProjectManager
/**
* Registers this gem repo with the current engine.
* @param repoUri the absolute filesystem path or url to the gem repo.
* @return true on success, false on failure.
* @return an outcome with a string error message on failure.
*/
virtual bool AddGemRepo(const QString& repoUri) = 0;
virtual AZ::Outcome<void, AZStd::string> AddGemRepo(const QString& repoUri) = 0;
/**
* Unregisters this gem repo with the current engine.