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

Commit 61d3a29

Browse files
jdxelbandito
authored andcommitted
fix: handle epipe errors
1 parent 75679b0 commit 61d3a29

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

example/ls.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class LS extends Command {
1212
dir: flags.string({
1313
char: 'd',
1414
default: process.cwd(),
15+
required: true,
1516
}),
1617
}
1718

@@ -25,4 +26,4 @@ class LS extends Command {
2526
}
2627

2728
LS.run()
28-
.catch(require('@oclif/errors/handle'))
29+
.then(() => {}, require('@oclif/errors/handle'))

src/command.ts

+12
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export default abstract class Command {
112112
const g: any = global
113113
g['http-call'] = g['http-call'] || {}
114114
g['http-call']!.userAgent = this.config.userAgent
115+
this._swallowEPIPE()
115116
if (this._helpOverride()) return this._help()
116117
}
117118

@@ -164,4 +165,15 @@ export default abstract class Command {
164165
this.log(this.config.userAgent)
165166
return this.exit(0)
166167
}
168+
169+
/**
170+
* swallows stdout epipe errors
171+
* this occurs when stdout closes such as when piping to head
172+
*/
173+
protected _swallowEPIPE() {
174+
process.stdout.on('error', err => {
175+
if (err && err.code === 'EPIPE') return
176+
throw err
177+
})
178+
}
167179
}

0 commit comments

Comments
 (0)