Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken line buffers #773

Merged
merged 2 commits into from Jun 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 22 additions & 12 deletions packages/exec/src/toolrunner.ts
Expand Up @@ -84,7 +84,7 @@ export class ToolRunner extends events.EventEmitter {
data: Buffer,
strBuffer: string,
onLine: (line: string) => void
): void {
): string {
try {
let s = strBuffer + data.toString()
let n = s.indexOf(os.EOL)
Expand All @@ -98,10 +98,12 @@ export class ToolRunner extends events.EventEmitter {
n = s.indexOf(os.EOL)
}

strBuffer = s
return s
} catch (err) {
// streaming lines to console is best effort. Don't fail a build.
this._debug(`error processing line. Failed with error ${err}`)

return ''
}
}

Expand Down Expand Up @@ -440,7 +442,7 @@ export class ToolRunner extends events.EventEmitter {
this._getSpawnOptions(this.options, fileName)
)

const stdbuffer = ''
let stdbuffer = ''
if (cp.stdout) {
cp.stdout.on('data', (data: Buffer) => {
if (this.options.listeners && this.options.listeners.stdout) {
Expand All @@ -451,15 +453,19 @@ export class ToolRunner extends events.EventEmitter {
optionsNonNull.outStream.write(data)
}

this._processLineBuffer(data, stdbuffer, (line: string) => {
if (this.options.listeners && this.options.listeners.stdline) {
this.options.listeners.stdline(line)
stdbuffer = this._processLineBuffer(
data,
stdbuffer,
(line: string) => {
if (this.options.listeners && this.options.listeners.stdline) {
this.options.listeners.stdline(line)
}
}
})
)
})
}

const errbuffer = ''
let errbuffer = ''
if (cp.stderr) {
cp.stderr.on('data', (data: Buffer) => {
state.processStderr = true
Expand All @@ -478,11 +484,15 @@ export class ToolRunner extends events.EventEmitter {
s.write(data)
}

this._processLineBuffer(data, errbuffer, (line: string) => {
if (this.options.listeners && this.options.listeners.errline) {
this.options.listeners.errline(line)
errbuffer = this._processLineBuffer(
data,
errbuffer,
(line: string) => {
if (this.options.listeners && this.options.listeners.errline) {
this.options.listeners.errline(line)
}
}
})
)
})
}

Expand Down