Skip to content

Commit

Permalink
Fix broken line buffers (#773)
Browse files Browse the repository at this point in the history
* Fix broken line buffers

* Code style
  • Loading branch information
qRoC committed Jun 2, 2021
1 parent 439eace commit c503536
Showing 1 changed file with 22 additions and 12 deletions.
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 @@ -444,7 +446,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 @@ -455,15 +457,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 @@ -482,11 +488,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

0 comments on commit c503536

Please sign in to comment.