Skip to content

Commit

Permalink
fix: Pass Error Object to Callback When Reject A Falsy Value, fix issue-
Browse files Browse the repository at this point in the history
  • Loading branch information
Solo-steven committed Oct 11, 2022
1 parent a0a7b26 commit 43912bf
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/HookCodeFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ class HookCodeFactory {
}
code += `}), function(_err${tapIndex}) {\n`;
code += `if(_hasResult${tapIndex}) throw _err${tapIndex};\n`;
code += `if(!_err${tapIndex}) { ${onError(`new Error()`)};\n`
code += `return; }\n`;
code += onError(`_err${tapIndex}`);
code += "});\n";
break;
Expand Down
113 changes: 113 additions & 0 deletions lib/__tests__/__snapshots__/HookCodeFactory.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ _hasResult2 = true;
onResult(_result2);
}), function(_err2) {
if(_hasResult2) throw _err2;
if(!_err2) { onError(new Error());
;
return; }
onError(_err2);
});
"
Expand All @@ -81,6 +84,10 @@ _promise2.then(
},
function(_err2) {
if (_hasResult2) throw _err2;
if (!_err2) {
onError(new Error());
return;
}
onError(_err2);
}
);
Expand All @@ -98,6 +105,9 @@ _hasResult2 = true;
onDone();
}), function(_err2) {
if(_hasResult2) throw _err2;
if(!_err2) { onError(new Error());
;
return; }
onError(_err2);
});
"
Expand All @@ -120,6 +130,10 @@ _promise2.then(
},
function(_err2) {
if (_hasResult2) throw _err2;
if (!_err2) {
onError(new Error());
return;
}
onError(_err2);
}
);
Expand Down Expand Up @@ -245,6 +259,9 @@ _hasResult2 = true;
onResult(_result2);
}), function(_err2) {
if(_hasResult2) throw _err2;
if(!_err2) { onError(new Error());
;
return; }
onError(_err2);
});
"
Expand All @@ -267,6 +284,10 @@ _promise2.then(
},
function(_err2) {
if (_hasResult2) throw _err2;
if (!_err2) {
onError(new Error());
return;
}
onError(_err2);
}
);
Expand All @@ -284,6 +305,9 @@ _hasResult2 = true;
onDone();
}), function(_err2) {
if(_hasResult2) throw _err2;
if(!_err2) { onError(new Error());
;
return; }
onError(_err2);
});
"
Expand All @@ -306,6 +330,10 @@ _promise2.then(
},
function(_err2) {
if (_hasResult2) throw _err2;
if (!_err2) {
onError(new Error());
return;
}
onError(_err2);
}
);
Expand Down Expand Up @@ -446,6 +474,9 @@ _hasResult2 = true;
onResult(_result2);
}), function(_err2) {
if(_hasResult2) throw _err2;
if(!_err2) { onError(new Error());
;
return; }
onError(_err2);
});
"
Expand All @@ -471,6 +502,10 @@ _promise2.then(
},
function(_err2) {
if (_hasResult2) throw _err2;
if (!_err2) {
onError(new Error());
return;
}
onError(_err2);
}
);
Expand All @@ -491,6 +526,9 @@ _hasResult2 = true;
onDone();
}), function(_err2) {
if(_hasResult2) throw _err2;
if(!_err2) { onError(new Error());
;
return; }
onError(_err2);
});
"
Expand All @@ -516,6 +554,10 @@ _promise2.then(
},
function(_err2) {
if (_hasResult2) throw _err2;
if (!_err2) {
onError(new Error());
return;
}
onError(_err2);
}
);
Expand Down Expand Up @@ -618,6 +660,9 @@ onDone();
}
}), function(_err2) {
if(_hasResult2) throw _err2;
if(!_err2) { onError(2, new Error());
;
return; }
onError(2, _err2);
});
}
Expand Down Expand Up @@ -686,6 +731,10 @@ exports[`HookCodeFactory taps (mixed) callTapsLooping 2`] = `
},
function(_err2) {
if (_hasResult2) throw _err2;
if (!_err2) {
onError(2, new Error());
return;
}
onError(2, _err2);
}
);
Expand Down Expand Up @@ -778,6 +827,11 @@ _done();
}
}), function(_err2) {
if(_hasResult2) throw _err2;
if(!_err2) { if(_counter > 0) {
onError(2, new Error());
}
;
return; }
if(_counter > 0) {
onError(2, _err2);
}
Expand Down Expand Up @@ -860,6 +914,12 @@ exports[`HookCodeFactory taps (mixed) callTapsParallel 2`] = `
},
function(_err2) {
if (_hasResult2) throw _err2;
if (!_err2) {
if (_counter > 0) {
onError(2, new Error());
}
return;
}
if (_counter > 0) {
onError(2, _err2);
}
Expand All @@ -885,6 +945,9 @@ onDone();
});
}), function(_err2) {
if(_hasResult2) throw _err2;
if(!_err2) { onError(2, new Error());
;
return; }
onError(2, _err2);
});
}
Expand Down Expand Up @@ -936,6 +999,10 @@ exports[`HookCodeFactory taps (mixed) callTapsSeries 2`] = `
},
function(_err2) {
if (_hasResult2) throw _err2;
if (!_err2) {
onError(2, new Error());
return;
}
onError(2, _err2);
}
);
Expand Down Expand Up @@ -1013,6 +1080,9 @@ _next1();
}
}), function(_err1) {
if(_hasResult1) throw _err1;
if(!_err1) { onError(1, new Error());
;
return; }
onError(1, _err1);
});
}
Expand Down Expand Up @@ -1084,6 +1154,10 @@ exports[`HookCodeFactory taps (mixed2) callTapsLooping 2`] = `
},
function(_err1) {
if (_hasResult1) throw _err1;
if (!_err1) {
onError(1, new Error());
return;
}
onError(1, _err1);
}
);
Expand Down Expand Up @@ -1150,6 +1224,11 @@ _done();
}
}), function(_err1) {
if(_hasResult1) throw _err1;
if(!_err1) { if(_counter > 0) {
onError(1, new Error());
}
;
return; }
if(_counter > 0) {
onError(1, _err1);
}
Expand Down Expand Up @@ -1227,6 +1306,12 @@ exports[`HookCodeFactory taps (mixed2) callTapsParallel 2`] = `
},
function(_err1) {
if (_hasResult1) throw _err1;
if (!_err1) {
if (_counter > 0) {
onError(1, new Error());
}
return;
}
if (_counter > 0) {
onError(1, _err1);
}
Expand Down Expand Up @@ -1285,6 +1370,9 @@ onDone();
});
}), function(_err1) {
if(_hasResult1) throw _err1;
if(!_err1) { onError(1, new Error());
;
return; }
onError(1, _err1);
});
}
Expand Down Expand Up @@ -1352,6 +1440,10 @@ function _next0() {
},
function(_err1) {
if (_hasResult1) throw _err1;
if (!_err1) {
onError(1, new Error());
return;
}
onError(1, _err1);
}
);
Expand Down Expand Up @@ -1779,6 +1871,9 @@ onDone();
}
}), function(_err0) {
if(_hasResult0) throw _err0;
if(!_err0) { onError(0, new Error());
;
return; }
onError(0, _err0);
});
} while(_loop);
Expand Down Expand Up @@ -1817,6 +1912,10 @@ exports[`HookCodeFactory taps (single promise) callTapsLooping 2`] = `
},
function(_err0) {
if (_hasResult0) throw _err0;
if (!_err0) {
onError(0, new Error());
return;
}
onError(0, _err0);
}
);
Expand All @@ -1842,6 +1941,9 @@ onDone();
});
}), function(_err0) {
if(_hasResult0) throw _err0;
if(!_err0) { onError(0, new Error());
;
return; }
onError(0, _err0);
});
"
Expand Down Expand Up @@ -1873,6 +1975,10 @@ _promise0.then(
},
function(_err0) {
if (_hasResult0) throw _err0;
if (!_err0) {
onError(0, new Error());
return;
}
onError(0, _err0);
}
);
Expand All @@ -1894,6 +2000,9 @@ onDone();
});
}), function(_err0) {
if(_hasResult0) throw _err0;
if(!_err0) { onError(0, new Error());
;
return; }
onError(0, _err0);
});
"
Expand Down Expand Up @@ -1925,6 +2034,10 @@ _promise0.then(
},
function(_err0) {
if (_hasResult0) throw _err0;
if (!_err0) {
onError(0, new Error());
return;
}
onError(0, _err0);
}
);
Expand Down

0 comments on commit 43912bf

Please sign in to comment.