Skip to content

Commit

Permalink
squash! update test-stdout-close-catch
Browse files Browse the repository at this point in the history
  • Loading branch information
joyeecheung committed Mar 3, 2018
1 parent babd2da commit 9620e7b
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,23 @@ function message(key, args) {
* @returns {Error}
*/
function uvException(ctx) {
const err = new Error();
const [ code, uvmsg ] = errmap.get(ctx.errno);
let message = `${code}: ${uvmsg}, ${ctx.syscall}`;

let path;
let dest;
if (ctx.path) {
path = ctx.path.toString();
message += ` '${path}'`;
}
if (ctx.dest) {
dest = ctx.dest.toString();
message += ` -> '${dest}'`;
}

// Pass the message to the constructor instead of setting it on the object
// to make sure it is the same as the one created in C++
const err = new Error(message);

for (const prop of Object.keys(ctx)) {
if (prop === 'message' || prop === 'path' || prop === 'dest') {
Expand All @@ -435,20 +451,13 @@ function uvException(ctx) {
err[prop] = ctx[prop];
}

const [ code, uvmsg ] = errmap.get(ctx.errno);
err.code = code;
let message = `${code}: ${uvmsg}, ${ctx.syscall}`;
if (ctx.path) {
const path = ctx.path.toString();
message += ` '${path}'`;
if (path) {
err.path = path;
}
if (ctx.dest) {
const dest = ctx.dest.toString();
message += ` -> '${dest}'`;
if (dest) {
err.dest = dest;
}
err.message = message;

Error.captureStackTrace(err, uvException);
return err;
Expand Down

0 comments on commit 9620e7b

Please sign in to comment.