Skip to content

Commit

Permalink
fix(core): Handles promise construction bodies which throw exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
grantila committed Jun 30, 2019
1 parent a45d11f commit 38cd27e
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions register.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,36 @@ process.on( "unhandledRejection", ( reason, promise ) =>
);
} );

const state = { resolve: null, reject: null };

class TraceablePromise extends Promise
{
constructor( executor )
{
super( wrappedExecutor );

function wrappedExecutor( ...args )
function wrappedExecutor( resolve, reject )
{
return executor( ...args );
state.resolve = resolve;
state.reject = reject;
}

const resolve = state.resolve;
const reject = state.reject;
state.resolve = null;
state.reject = null;

const err = new Error( "Non-failing tracing error" );
this.__tracedError = err;

try
{
executor( resolve, reject );
}
catch ( err )
{
reject( err );
}
}
}

Expand Down

0 comments on commit 38cd27e

Please sign in to comment.