-
Notifications
You must be signed in to change notification settings - Fork 30.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tty: convert to internal/errors using SystemError
PR-URL: #16567 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
- Loading branch information
Showing
4 changed files
with
77 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,57 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
const tty = require('tty'); | ||
|
||
assert.throws(() => { | ||
new tty.WriteStream(-1); | ||
}, common.expectsError({ | ||
code: 'ERR_INVALID_FD', | ||
type: RangeError, | ||
message: '"fd" must be a positive integer: -1' | ||
}) | ||
common.expectsError( | ||
() => new tty.WriteStream(-1), | ||
{ | ||
code: 'ERR_INVALID_FD', | ||
type: RangeError, | ||
message: '"fd" must be a positive integer: -1' | ||
} | ||
); | ||
|
||
const err_regex = common.isWindows ? | ||
/^Error: EBADF: bad file descriptor, uv_tty_init$/ : | ||
/^Error: EINVAL: invalid argument, uv_tty_init$/; | ||
assert.throws(() => { | ||
let fd = 2; | ||
// Get first known bad file descriptor. | ||
try { | ||
while (fs.fstatSync(++fd)); | ||
} catch (e) { } | ||
new tty.WriteStream(fd); | ||
}, err_regex); | ||
{ | ||
const message = common.isWindows ? | ||
'bad file descriptor: EBADF [uv_tty_init]' : | ||
'invalid argument: EINVAL [uv_tty_init]'; | ||
|
||
assert.throws(() => { | ||
new tty.ReadStream(-1); | ||
}, common.expectsError({ | ||
code: 'ERR_INVALID_FD', | ||
type: RangeError, | ||
message: '"fd" must be a positive integer: -1' | ||
}) | ||
); | ||
common.expectsError( | ||
() => { | ||
let fd = 2; | ||
// Get first known bad file descriptor. | ||
try { | ||
while (fs.fstatSync(++fd)); | ||
} catch (e) { } | ||
new tty.WriteStream(fd); | ||
}, { | ||
code: 'ERR_SYSTEM_ERROR', | ||
type: Error, | ||
message | ||
} | ||
); | ||
|
||
common.expectsError( | ||
() => { | ||
let fd = 2; | ||
// Get first known bad file descriptor. | ||
try { | ||
while (fs.fstatSync(++fd)); | ||
} catch (e) { } | ||
new tty.ReadStream(fd); | ||
}, { | ||
code: 'ERR_SYSTEM_ERROR', | ||
type: Error, | ||
message | ||
}); | ||
} | ||
|
||
assert.throws(() => { | ||
let fd = 2; | ||
// Get first known bad file descriptor. | ||
try { | ||
while (fs.fstatSync(++fd)); | ||
} catch (e) { } | ||
new tty.ReadStream(fd); | ||
}, err_regex); | ||
common.expectsError( | ||
() => new tty.ReadStream(-1), | ||
{ | ||
code: 'ERR_INVALID_FD', | ||
type: RangeError, | ||
message: '"fd" must be a positive integer: -1' | ||
} | ||
); |