Skip to content

Commit

Permalink
Merge pull request #5528 from rstudio/bugfix/notebook-output-truncation
Browse files Browse the repository at this point in the history
avoid IDE hang with excessive console output (#5518)
  • Loading branch information
jmcphers committed Oct 17, 2019
2 parents 394689b + 9c9246f commit c60306f
Showing 1 changed file with 17 additions and 0 deletions.
Expand Up @@ -27,6 +27,7 @@
import org.rstudio.studio.client.RStudioGinjector;
import org.rstudio.studio.client.common.debugging.model.UnhandledError;
import org.rstudio.studio.client.common.debugging.ui.ConsoleError;
import org.rstudio.studio.client.common.satellite.Satellite;
import org.rstudio.studio.client.rmarkdown.model.NotebookFrameMetadata;
import org.rstudio.studio.client.rmarkdown.model.NotebookHtmlMetadata;
import org.rstudio.studio.client.rmarkdown.model.NotebookPlotMetadata;
Expand Down Expand Up @@ -100,6 +101,11 @@ public void showConsoleError(String error)
public void showConsoleOutput(JsArray<JsArrayEx> output)
{
initializeOutput(RmdChunkOutputUnit.TYPE_TEXT);

// track number of newlines in output
int newlineCount = 0;
int maxCount = Satellite.isCurrentWindowSatellite() ? 10000 : 2000;

for (int i = 0; i < output.length(); i++)
{
// the first element is the output, and the second is the text; if we
Expand Down Expand Up @@ -130,6 +136,17 @@ public void showConsoleOutput(JsArray<JsArrayEx> output)

vconsole_.submit(outputText, classOfOutput(outputType));
}

// avoid hanging the IDE by displaying too much output
// https://github.com/rstudio/rstudio/issues/5518
newlineCount += StringUtil.countMatches(outputText, '\n');
if (newlineCount >= maxCount)
{
vconsole_.submit(
"\n[Output truncated]",
classOfOutput(ChunkConsolePage.CONSOLE_ERROR));
break;
}
}
}

Expand Down

0 comments on commit c60306f

Please sign in to comment.