Skip to content

Commit 6832486

Browse files
committed
Formatter: fix crashes
Sometimes, formatters fails. Reason is that we are not reading the output channels. Read them before closing the application.
1 parent e3507be commit 6832486

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/plugins/CodeFormat/CodeFormat.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,19 +250,20 @@ QFuture<CommandArgs> CodeFormatPlugin::runFormat(const QString &fileName, const
250250
return result;
251251
}
252252

253+
// Always drain both channels to prevent pipe-buffer stalls on subsequent runs.
254+
auto stdoutData = proc.readAllStandardOutput();
255+
auto stderrData = proc.readAllStandardError();
253256
if (proc.exitCode() != 0) {
254-
auto processStderr = proc.readAllStandardError();
255257
qDebug() << "CodeFormatPlugin:" << indenter->binary << "code:" << proc.exitCode();
256-
qDebug() << "CodeFormatPlugin stderr:" << processStderr;
258+
qDebug() << "CodeFormatPlugin stderr:" << stderrData;
257259
result[GlobalArguments::ExitCode] = proc.exitCode();
258-
result[GlobalArguments::ErrorMessage] = processStderr;
260+
result[GlobalArguments::ErrorMessage] = stderrData;
259261
return result;
260262
}
261263

262264
if (indenter->processStdout) {
263-
auto out = proc.readAllStandardOutput();
264-
if (!out.isEmpty()) {
265-
result[GlobalArguments::Content] = QString::fromUtf8(out);
265+
if (!stdoutData.isEmpty()) {
266+
result[GlobalArguments::Content] = QString::fromUtf8(stdoutData);
266267
return result;
267268
} else {
268269
qDebug() << "CodeFormatPlugin: stdout is empty for" << indenter->binary;

0 commit comments

Comments
 (0)