Docker: Improve error reporting

Change-Id: I7ff4d54e1a4a82baa267419930f61206f238ebce
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2024-10-11 06:49:37 +02:00
parent 2008d6d1ff
commit 676892cfb5

View File

@@ -193,12 +193,13 @@ public:
expected_str<Environment> environment(); expected_str<Environment> environment();
CommandLine withDockerExecCmd(const CommandLine &cmd, expected_str<CommandLine> withDockerExecCmd(
const std::optional<Environment> &env = std::nullopt, const CommandLine &cmd,
const std::optional<FilePath> &workDir = std::nullopt, const std::optional<Environment> &env = std::nullopt,
bool interactive = false, const std::optional<FilePath> &workDir = std::nullopt,
bool withPty = false, bool interactive = false,
bool withMarker = true); bool withPty = false,
bool withMarker = true);
bool prepareForBuild(const Target *target); bool prepareForBuild(const Target *target);
Tasks validateMounts() const; Tasks validateMounts() const;
@@ -374,15 +375,25 @@ void DockerProcessImpl::start()
const bool interactive = m_setup.m_processMode == ProcessMode::Writer const bool interactive = m_setup.m_processMode == ProcessMode::Writer
|| !m_setup.m_writeData.isEmpty() || inTerminal; || !m_setup.m_writeData.isEmpty() || inTerminal;
const CommandLine fullCommandLine const expected_str<CommandLine> fullCommandLine = m_devicePrivate->withDockerExecCmd(
= m_devicePrivate->withDockerExecCmd(m_setup.m_commandLine, m_setup.m_commandLine,
m_setup.m_environment, m_setup.m_environment,
m_setup.m_workingDirectory, m_setup.m_workingDirectory,
interactive, interactive,
inTerminal, inTerminal,
!m_process.ptyData().has_value()); !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(); m_process.start();
} }
@@ -610,8 +621,8 @@ DockerDevice::DockerDevice()
return fileAccess->get(); return fileAccess->get();
} }
qCWarning(dockerDeviceLog) << "Failed to start CmdBridge:" << fAccess.error() qCWarning(dockerDeviceLog).noquote() << "Failed to start CmdBridge:" << fAccess.error()
<< ", falling back to slow direct access"; << ", falling back to slow direct access";
*fileAccess = std::make_unique<DockerFallbackFileAccess>(rootPath()); *fileAccess = std::make_unique<DockerFallbackFileAccess>(rootPath());
return fileAccess->get(); return fileAccess->get();
@@ -679,15 +690,16 @@ expected_str<void> DockerDevice::updateContainerAccess() const
return d->updateContainerAccess(); return d->updateContainerAccess();
} }
CommandLine DockerDevicePrivate::withDockerExecCmd(const CommandLine &cmd, expected_str<CommandLine> DockerDevicePrivate::withDockerExecCmd(
const std::optional<Environment> &env, const CommandLine &cmd,
const std::optional<FilePath> &workDir, const std::optional<Environment> &env,
bool interactive, const std::optional<FilePath> &workDir,
bool withPty, bool interactive,
bool withMarker) bool withPty,
bool withMarker)
{ {
if (!updateContainerAccess()) if (const auto result = updateContainerAccess(); !result)
return {}; return make_unexpected(result.error());
CommandLine dockerCmd{settings().dockerBinaryPath(), {"exec"}}; CommandLine dockerCmd{settings().dockerBinaryPath(), {"exec"}};
@@ -1101,8 +1113,12 @@ expected_str<void> DockerDevicePrivate::fetchSystemEnviroment()
if (!result) if (!result)
return result; return result;
const expected_str<CommandLine> fullCommandLine = withDockerExecCmd(CommandLine{"env"});
if (!fullCommandLine)
return make_unexpected(fullCommandLine.error());
Process proc; Process proc;
proc.setCommand(withDockerExecCmd(CommandLine{"env"})); proc.setCommand(*fullCommandLine);
proc.runBlocking(); proc.runBlocking();
const QString remoteOutput = proc.cleanedStdOut(); const QString remoteOutput = proc.cleanedStdOut();