From 676892cfb5e3501068ec4b38ae32c9999d39a140 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Fri, 11 Oct 2024 06:49:37 +0200 Subject: [PATCH] Docker: Improve error reporting Change-Id: I7ff4d54e1a4a82baa267419930f61206f238ebce Reviewed-by: hjk --- src/plugins/docker/dockerdevice.cpp | 66 ++++++++++++++++++----------- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/src/plugins/docker/dockerdevice.cpp b/src/plugins/docker/dockerdevice.cpp index 78cbfa32e55..0f7d872ba12 100644 --- a/src/plugins/docker/dockerdevice.cpp +++ b/src/plugins/docker/dockerdevice.cpp @@ -193,12 +193,13 @@ public: expected_str environment(); - CommandLine withDockerExecCmd(const CommandLine &cmd, - const std::optional &env = std::nullopt, - const std::optional &workDir = std::nullopt, - bool interactive = false, - bool withPty = false, - bool withMarker = true); + expected_str withDockerExecCmd( + const CommandLine &cmd, + const std::optional &env = std::nullopt, + const std::optional &workDir = std::nullopt, + bool interactive = false, + bool withPty = false, + bool withMarker = true); bool prepareForBuild(const Target *target); Tasks validateMounts() const; @@ -374,15 +375,25 @@ void DockerProcessImpl::start() const bool interactive = m_setup.m_processMode == ProcessMode::Writer || !m_setup.m_writeData.isEmpty() || inTerminal; - const CommandLine fullCommandLine - = m_devicePrivate->withDockerExecCmd(m_setup.m_commandLine, - m_setup.m_environment, - m_setup.m_workingDirectory, - interactive, - inTerminal, - !m_process.ptyData().has_value()); + const expected_str fullCommandLine = m_devicePrivate->withDockerExecCmd( + m_setup.m_commandLine, + m_setup.m_environment, + m_setup.m_workingDirectory, + interactive, + inTerminal, + !m_process.ptyData().has_value()); - m_process.setCommand(fullCommandLine); + if (!fullCommandLine) { + emit done(ProcessResultData{ + -1, + QProcess::ExitStatus::CrashExit, + QProcess::ProcessError::FailedToStart, + fullCommandLine.error(), + }); + return; + } + + m_process.setCommand(*fullCommandLine); m_process.start(); } @@ -610,8 +621,8 @@ DockerDevice::DockerDevice() return fileAccess->get(); } - qCWarning(dockerDeviceLog) << "Failed to start CmdBridge:" << fAccess.error() - << ", falling back to slow direct access"; + qCWarning(dockerDeviceLog).noquote() << "Failed to start CmdBridge:" << fAccess.error() + << ", falling back to slow direct access"; *fileAccess = std::make_unique(rootPath()); return fileAccess->get(); @@ -679,15 +690,16 @@ expected_str DockerDevice::updateContainerAccess() const return d->updateContainerAccess(); } -CommandLine DockerDevicePrivate::withDockerExecCmd(const CommandLine &cmd, - const std::optional &env, - const std::optional &workDir, - bool interactive, - bool withPty, - bool withMarker) +expected_str DockerDevicePrivate::withDockerExecCmd( + const CommandLine &cmd, + const std::optional &env, + const std::optional &workDir, + bool interactive, + bool withPty, + bool withMarker) { - if (!updateContainerAccess()) - return {}; + if (const auto result = updateContainerAccess(); !result) + return make_unexpected(result.error()); CommandLine dockerCmd{settings().dockerBinaryPath(), {"exec"}}; @@ -1101,8 +1113,12 @@ expected_str DockerDevicePrivate::fetchSystemEnviroment() if (!result) return result; + const expected_str fullCommandLine = withDockerExecCmd(CommandLine{"env"}); + if (!fullCommandLine) + return make_unexpected(fullCommandLine.error()); + Process proc; - proc.setCommand(withDockerExecCmd(CommandLine{"env"})); + proc.setCommand(*fullCommandLine); proc.runBlocking(); const QString remoteOutput = proc.cleanedStdOut();