Skip to content

Commit f1d59a0

Browse files
committed
Promise.thenFinally should not suppress the original failure.
Fixes issue 7156.
1 parent 227674b commit f1d59a0

File tree

5 files changed

+62
-7
lines changed

5 files changed

+62
-7
lines changed

javascript/node/selenium-webdriver/CHANGES.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v2.43.0-dev
2+
3+
* FIXED: 7156: `Promise#thenFinally` should not suppress original error
4+
15
## v2.42.0
26

37
* Removed deprecated functions `Promise#addCallback()`,

javascript/node/selenium-webdriver/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "selenium-webdriver",
3-
"version": "2.42.0",
3+
"version": "2.43.0-dev",
44
"description": "The official WebDriver JavaScript bindings from the Selenium project",
55
"keywords": [
66
"automation",

javascript/webdriver/promise.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,15 @@ webdriver.promise.Promise.prototype.thenCatch = function(errback) {
184184
* @template R
185185
*/
186186
webdriver.promise.Promise.prototype.thenFinally = function(callback) {
187-
return this.then(callback, callback);
187+
return this.then(callback, function(err) {
188+
var value = callback();
189+
if (webdriver.promise.isPromise(value)) {
190+
return value.then(function() {
191+
throw err;
192+
});
193+
}
194+
throw err;
195+
});
188196
};
189197

190198

javascript/webdriver/test/promise_flow_test.html

+10-5
Original file line numberDiff line numberDiff line change
@@ -1175,10 +1175,13 @@
11751175

11761176
scheduleAction('doFoo and throw', function() {
11771177
webdriver.test.testutil.messages.push('foo');
1178-
throw new Error('ouch');
1178+
throw STUB_ERROR;
11791179
}).then(goog.partial(schedulePush, 'bar')).
11801180
thenFinally(goog.partial(schedulePush, 'baz'));
1181-
runAndExpectSuccess(assertingMessages('foo', 'baz'));
1181+
runAndExpectFailure(function(e) {
1182+
assertIsStubError(e);
1183+
webdriver.test.testutil.assertMessages('foo', 'baz');
1184+
});
11821185
}
11831186

11841187

@@ -1199,11 +1202,13 @@
11991202
throw STUB_ERROR;
12001203
});
12011204
}).
1202-
thenFinally(function(e) {
1203-
assertIsStubError(e);
1205+
thenFinally(function() {
12041206
return schedulePush('baz');
12051207
});
1206-
runAndExpectSuccess(assertingMessages('foo', 'bar', 'baz'));
1208+
runAndExpectFailure(function(e) {
1209+
assertIsStubError(e);
1210+
webdriver.test.testutil.assertMessages('foo', 'bar' , 'baz');
1211+
});
12071212
}
12081213

12091214

javascript/webdriver/test/promise_test.html

+38
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,44 @@
248248
}
249249

250250

251+
function testThenFinally_nonFailingCallbackDoesNotSuppressOriginalError() {
252+
var done = callbackHelper(assertIsStubError);
253+
webdriver.promise.rejected(STUB_ERROR).
254+
thenFinally(goog.nullFunction).
255+
thenCatch(done);
256+
done.assertCalled();
257+
}
258+
259+
260+
function testThenFinally_failingCallbackSuppressesOriginalError() {
261+
var done = callbackHelper(assertIsStubError);
262+
webdriver.promise.rejected(new Error('original')).
263+
thenFinally(throwStubError).
264+
thenCatch(done);
265+
done.assertCalled();
266+
}
267+
268+
269+
function testThenFinally_callbackThrowsAfterFulfilledPromise() {
270+
var done = callbackHelper(assertIsStubError);
271+
webdriver.promise.fulfilled().
272+
thenFinally(throwStubError).
273+
thenCatch(done);
274+
done.assertCalled();
275+
}
276+
277+
278+
function testThenFinally_callbackReturnsRejectedPromise() {
279+
var done = callbackHelper(assertIsStubError);
280+
webdriver.promise.fulfilled().
281+
thenFinally(function() {
282+
return webdriver.promise.rejected(STUB_ERROR);
283+
}).
284+
thenCatch(done);
285+
done.assertCalled();
286+
}
287+
288+
251289
function testChainingThen_AllResolved() {
252290
var callbacks = [
253291
callbackHelper(function(value) {

0 commit comments

Comments
 (0)