Skip to content

Commit 190e3f9

Browse files
committed
Remove throw and replace with message and non-zero exit code
1 parent 59d43c5 commit 190e3f9

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

lib/node_modules/@stdlib/string/lowercase/bin/cli

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ var lowercase = require( './../lib' );
1818
* @private
1919
* @param {(Error|null)} error - error object
2020
* @param {Buffer} data - data
21-
* @throws {Error} unexpected error
2221
* @returns {void}
2322
*/
2423
function onRead( error, data ) {
24+
/* eslint-disable no-console */
2525
if ( error ) {
26-
throw error;
26+
process.exitCode = 1;
27+
return console.error( 'Error: %s', error.message );
2728
}
28-
console.log( lowercase( data.toString() ) ); // eslint-disable-line no-console
29+
console.log( lowercase( data.toString() ) );
2930
} // end FUNCTION onRead()
3031

3132

lib/node_modules/@stdlib/string/lowercase/test/test.cli.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ tape( 'the command-line interface supports use as a standard stream', opts, func
163163
}
164164
});
165165

166-
tape( 'when used as a standard stream, if an error is encountered when reading from `stdin`, the command-line interface throws an error', opts, function test( t ) {
166+
tape( 'when used as a standard stream, if an error is encountered when reading from `stdin`, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) {
167167
var script;
168168
var opts;
169169
var cmd;
@@ -187,12 +187,13 @@ tape( 'when used as a standard stream, if an error is encountered when reading f
187187

188188
exec( cmd.join( ' ' ), opts, done );
189189

190-
function done( error ) {
190+
function done( error, stdout, stderr ) {
191191
if ( error ) {
192192
t.pass( error.message );
193-
} else {
194-
t.fail( 'should return an error' );
193+
t.strictEqual( error.code, 1, 'expected exit code' );
195194
}
195+
t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' );
196+
t.strictEqual( stderr.toString(), 'Error: beep\n', 'expected value' );
196197
t.end();
197198
}
198199
});

0 commit comments

Comments
 (0)