Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
fix: handle epipe errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx authored and elbandito committed Feb 27, 2019
1 parent 75679b0 commit 61d3a29
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion example/ls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class LS extends Command {
dir: flags.string({
char: 'd',
default: process.cwd(),
required: true,
}),
}

Expand All @@ -25,4 +26,4 @@ class LS extends Command {
}

LS.run()
.catch(require('@oclif/errors/handle'))
.then(() => {}, require('@oclif/errors/handle'))
12 changes: 12 additions & 0 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export default abstract class Command {
const g: any = global
g['http-call'] = g['http-call'] || {}
g['http-call']!.userAgent = this.config.userAgent
this._swallowEPIPE()
if (this._helpOverride()) return this._help()
}

Expand Down Expand Up @@ -164,4 +165,15 @@ export default abstract class Command {
this.log(this.config.userAgent)
return this.exit(0)
}

/**
* swallows stdout epipe errors
* this occurs when stdout closes such as when piping to head
*/
protected _swallowEPIPE() {
process.stdout.on('error', err => {
if (err && err.code === 'EPIPE') return
throw err
})
}
}

0 comments on commit 61d3a29

Please sign in to comment.