Skip to content

Commit

Permalink
Refactor error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryte committed Aug 17, 2019
1 parent e006d91 commit 9efdb42
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
15 changes: 6 additions & 9 deletions lib/node_modules/@stdlib/repl/lib/commands/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,8 @@ function command( repl ) {
* @private
*/
function onDrain() {
try {
debug( 'Loading a file...' );
repl.load( fpath, clbk );
} catch ( error ) {
debug( 'Error: %s', error.message );

// TODO: determine whether we need to perform ANSI escape magic here! (the error message gets printed on the wrong line!)
repl._ostream.write( 'Error: '+error.message+'\n' );
}
debug( 'Loading a file...' );
repl.load( fpath, clbk );
}

/**
Expand All @@ -85,7 +78,11 @@ function command( repl ) {
*/
function clbk( error ) {
if ( error ) {
// NOTE: we can assume that the error pertains to actually reading the file (e.g., loading from disk) and NOT the line-by-line evaluation, where error handling should be handled separately...
debug( 'Error: %s', error.message );

// TODO: determine whether we need to perform ANSI escape magic here! (the error message gets printed on the wrong line!)
repl._ostream.write( 'Error: '+error.message+'\n' );
return;
}
debug( 'Successfully loaded file.' );
Expand Down
1 change: 0 additions & 1 deletion lib/node_modules/@stdlib/repl/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,6 @@ setNonEnumerableReadOnly( REPL.prototype, 'load', function load( fpath, clbk ) {
file = readFileSync( fpath, 'utf8' );
if ( file instanceof Error ) {
debug( 'Error: %s', file.message );
this._ostream.write( 'Error: '+file.message+'\n' );
clbk( file );
return;
}
Expand Down

0 comments on commit 9efdb42

Please sign in to comment.