question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Terminal doesn't flush all line data before firing onExit

See original GitHub issue
  • VSCode Version: 1.43.0
  • OS Version: Windows 10 version 1809
  • Does this issue occur on the latest insiders build?: Yes
  • Does this issue occur when all extensions are disabled?: Yes

Steps to Reproduce:

  1. Create a Task which uses CustomExecution to output to a PseudoTerminal and specify one or more ProblemMatchers which are relevant to the Task’s output.
  2. Run the Task. Its output seemingly will not be processed by the specified ProblemMatchers. At least, the effects are not applied - I cannot CTRL+click on file names, problems are not reported in the “Problems” tab, etc.

Sample code:

import * as vscode from "vscode";
import { exec } from "child_process";

// Simply run tsc and output the results to the terminal
class MyBuildTaskTerminal implements vscode.Pseudoterminal {
    private writeEmitter = new vscode.EventEmitter<string>();
    onDidWrite: vscode.Event<string> = this.writeEmitter.event;
    private closeEmitter = new vscode.EventEmitter<void>();
    onDidClose?: vscode.Event<void> = this.closeEmitter.event;

    open(_initialDimensions: vscode.TerminalDimensions | undefined): void {
        this.doBuild();
    }

    close(): void {
    }

    private async doBuild(): Promise<void> {
        this.writeEmitter.fire("Starting build...\r\n");

        // non-existent.ts doesn't exist and will output an error, but there will
        // be no corresponding entry in the "Problems" tab.
        //
        // Similarly, if the file did exist but contained errors (and I prefixed the
        // command with "cd /path/to/workspace/dir && "), I wouldn't be able
        // to CTRL+click the file's path to go to the location of the problem
        exec("tsc non-existent.ts", (_error, stdout, stderr) => {
            this.writeEmitter.fire(stdout);
            this.writeEmitter.fire(stderr);
            this.closeEmitter.fire();
        });
    }
}

const myTask = new vscode.Task(
    { type: "myType" },
    vscode.TaskScope.Workspace,
    "myTask",
    "mySource",
    new vscode.CustomExecution(async () => {
        // Pseudo-terminal implementing some task which fires onDidWrite()'s emitter
        // to output text. For this example, it runs tsc and outputs any compile errors
       return new MyBuildTaskTerminal();
    }),
    "$tsc"  // TypeScript errors should be picked up
);
vscode.tasks.executeTask(myTask);

VSCode behaves as expected if I change the line

new vscode.CustomExecution(...)

to

new vscode.ShellExecution("tsc non-existent.ts")

In my actual project, the Task’s logic is more complex and I can’t simply use ShellExecution.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
alexr00commented, May 26, 2020

@Tyriar I added setTimeout hack so that my onLineData listener isn’t disposed until later, giving “enough” time after when exit is fired for the rest of the line data to come through.

1reaction
alexr00commented, Mar 18, 2020

I modified the task provider sample to make a super simple example:

class CustomBuildTaskTerminal implements vscode.Pseudoterminal {
	private writeEmitter = new vscode.EventEmitter<string>();
	onDidWrite: vscode.Event<string> = this.writeEmitter.event;
	private closeEmitter = new vscode.EventEmitter<void>();
	onDidClose?: vscode.Event<void> = this.closeEmitter.event;

	open(initialDimensions: vscode.TerminalDimensions | undefined): void {
		this.doBuild();
	}

	close(): void {
	}

	private async doBuild(): Promise<void> {
		return new Promise<void>((resolve) => {
			this.writeEmitter.fire('src/customTaskProvider.ts:92:8 - error TS2551: Property \'doBuild\' does not exist on type \'CustomBuildTaskTerminal\'. Did you mean \'doBild\'?\r\n');
			this.writeEmitter.fire('\r\n');
			this.writeEmitter.fire('92      this.doBuild();\r\n');
			this.writeEmitter.fire('             ~~~~~~~\r\n');
			this.writeEmitter.fire('\r\n');
			this.writeEmitter.fire('  src/customTaskProvider.ts:99:16\r\n');
			this.writeEmitter.fire('    99  private async doBild(): Promise<void> {\r\n');
			this.writeEmitter.fire('                      ~~~~~~\r\n');
			this.writeEmitter.fire('\r\n');
			this.writeEmitter.fire('    \'doBild\' is declared here.\r\n');
			this.writeEmitter.fire('\r\n');
			this.writeEmitter.fire('\r\n');
			this.writeEmitter.fire('Found 1 error.');
			this.closeEmitter.fire();
		});
	}
}

Task for tasks.json:

        {
            "label": "custom with problem matcher",
            "type": "custombuildscript",
            "flavor": "32",
            "flags": [],
            "problemMatcher": "$tsc"
        }

When this runs without break points and with some logging, I can see that the the terminal is firing onExit before almost all of the onLineData. @Tyriar I thought there was something in place to prevent this now. How should I recommend folks handle this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does printf not flush after the call unless a newline is in ...
The stdout stream is line buffered by default, so will only display what's in the buffer after it reaches a newline (or when...
Read more >
Chromium Command Line Switches Cheat Sheet - Kapeli
The constant OS_WIN must be defined. /prefetch:# argument shared by all process types that don't have their own. It is likely that the...
Read more >
List of Chromium Command Line Switches - Peter Beverloo
List of Chromium Command Line Switches. There are lots of command lines which can be used with the Google Chrome browser. Some change...
Read more >
Keyboard Control - mpv.io
For example, before mpv --log-file f.txt would write a log to f.txt, ... any option given on the command line usually affects all...
Read more >
Issues closed in the 2.x development cycle - IPython
Just one bugfix: fixed bad CRCRLF line-endings in notebooks on Windows ... #5703: Notebook doesn't render with “ask me every time” cookie setting...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found