{"action":"created","issue":{"url":"https://api.github.com/repos/webdriverio/webdriverio/issues/1609","repository_url":"https://api.github.com/repos/webdriverio/webdriverio","labels_url":"https://api.github.com/repos/webdriverio/webdriverio/issues/1609/labels{/name}","comments_url":"https://api.github.com/repos/webdriverio/webdriverio/issues/1609/comments","events_url":"https://api.github.com/repos/webdriverio/webdriverio/issues/1609/events","html_url":"https://github.com/webdriverio/webdriverio/issues/1609","id":179036009,"number":1609,"title":"Inconsistent error stack in standalone mode","user":{"login":"jtlapp","id":138133,"avatar_url":"https://avatars.githubusercontent.com/u/138133?v=3","gravatar_id":"","url":"https://api.github.com/users/jtlapp","html_url":"https://github.com/jtlapp","followers_url":"https://api.github.com/users/jtlapp/followers","following_url":"https://api.github.com/users/jtlapp/following{/other_user}","gists_url":"https://api.github.com/users/jtlapp/gists{/gist_id}","starred_url":"https://api.github.com/users/jtlapp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jtlapp/subscriptions","organizations_url":"https://api.github.com/users/jtlapp/orgs","repos_url":"https://api.github.com/users/jtlapp/repos","events_url":"https://api.github.com/users/jtlapp/events{/privacy}","received_events_url":"https://api.github.com/users/jtlapp/received_events","type":"User","site_admin":false},"labels":[{"id":32695218,"url":"https://api.github.com/repos/webdriverio/webdriverio/labels/Bug","name":"Bug","color":"e10c02","default":false},{"id":450967126,"url":"https://api.github.com/repos/webdriverio/webdriverio/labels/PRs%20welcome!","name":"PRs welcome!","color":"0e8a16","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":29,"created_at":"2016-09-24T15:38:54Z","updated_at":"2016-12-14T23:42:04Z","closed_at":null,"body":"OS:  Mac OS X 10.11.4 x86_64\nNode: v6.3.1\nSelenium Version:  v2.53.1, with Core v2.53.1. Built from revision a36b8b1\nwebdriver.io: 4.2.16\n\nWhen a callback provided to `webdriver.io` throws an exception or returns a rejected promise, the client properly bubbles up the error, except when chaining `.end()`.\n\nI tested errors generated as follows:\n- `throw new Error(\"an exception happens here\")`\n- `return Promise.reject(new Error(\"a promise gets rejected\"))`\n- `return Promise.reject(\"a promise gets rejected\")`\n\nHere is a demonstration of throwing an exception that works properly:\n\n``` js\nvar promise = webdriverio\n    .remote(options).init()\n    .url('http://www.google.com')\n    .getTitle().then(function(title) {\n        throw new Error(\"an exception happens here\");\n        console.log('Title was: ' + title);\n    });\n    promise.end();\nshowError(promise);\n\nfunction showError(promise) {\n    if (typeof promise.then === 'function') {\n        promise.catch(function (err) {\n            if (err instanceof Error)\n                console.log(err);\n            else\n                console.log(\"Rejected promise: \"+ err);\n        });\n    }\n    else\n        console.log(\"not a promise\");\n}\n\n// Error: an exception happens here\n//     at Object.<anonymous> (/repos/arepo/tests/test_errs.js:26:15)\n//     at Object.exec (/repos/arepo/node_modules/webdriverio/build/lib/helpers/safeExecute.js:28:24)\n//     at Object.resolve (/repos/arepo/node_modules/webdriverio/build/lib/webdriverio.js:189:29)\n```\n\nIf we instead return the result of chaining `.end()`, we get this:\n\n``` js\nvar promise = webdriverio\n    .remote(options).init()\n    .url('http://www.google.com')\n    .getTitle().then(function(title) {\n        throw new Error(\"an exception happens here\");\n        console.log('Title was: ' + title);\n    })\n    .end();\nshowError(promise);\n\n// Error: an exception happens here\n//     at title() - getTitle.js:29:28\n//     at end() - webdriverio.js:16:6\n```\n\nFor completeness, here are comparisons of chaining vs not chaining returning rejected promises:\n\n``` js\n        return Promise.reject(new Error(\"a promise gets rejected\"));\n\n/* NOT CHAINED */\n// Error: a promise gets rejected\n//     at Object.<anonymous> (/repos/arepo/tests/test_errs.js:56:31)\n//     at Object.exec (/repos/arepo/node_modules/webdriverio/build/lib/helpers/safeExecute.js:28:24)\n//     at Object.resolve (/repos/arepo/node_modules/webdriverio/build/lib/webdriverio.js:189:29)\n\n/* CHAINED */\n// Error: a promise gets rejected\n//     at title() - getTitle.js:29:28\n//     at end() - test_errs.js:45:6\n```\n\n``` js\n        return Promise.reject(\"a promise gets rejected\");\n\n/* NOT CHAINED */\n// Rejected promise: a promise gets rejected\n\n/* CHAINED */\n// (nothing is output in this scenario)\n```\n\nI suspect a decision must be made about whether `.end()` should return a promise that propagates a callback error. If the answer is yes, it should be made consistent. If the answer is no, `.end()` should return no error information instead of a confused mix of information. The inconsistencies had me pulling my hair out looking for the proper resolution.\n\nMy preference is to be able to include include the following in my tests and have it properly propagate errors to the test harness:\n\n``` js\nvar t = require('tap');\n\nt.test(\"load the home page\", function (t) {\n    return webdriverio\n        .remote(options).init()\n        .url('http://www.google.com')\n        .getTitle().then(function(title) {\n            console.log('Title was: ' + title);\n        })\n        .end();\n});\n```\n\nNote that [`tap`](https://github.com/tapjs/node-tap) will handle properly returned promises in these error scenarios, reporting the errors.\n"},"comment":{"url":"https://api.github.com/repos/webdriverio/webdriverio/issues/comments/267191910","html_url":"https://github.com/webdriverio/webdriverio/issues/1609#issuecomment-267191910","issue_url":"https://api.github.com/repos/webdriverio/webdriverio/issues/1609","id":267191910,"user":{"login":"CSomerville","id":11085655,"avatar_url":"https://avatars.githubusercontent.com/u/11085655?v=3","gravatar_id":"","url":"https://api.github.com/users/CSomerville","html_url":"https://github.com/CSomerville","followers_url":"https://api.github.com/users/CSomerville/followers","following_url":"https://api.github.com/users/CSomerville/following{/other_user}","gists_url":"https://api.github.com/users/CSomerville/gists{/gist_id}","starred_url":"https://api.github.com/users/CSomerville/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CSomerville/subscriptions","organizations_url":"https://api.github.com/users/CSomerville/orgs","repos_url":"https://api.github.com/users/CSomerville/repos","events_url":"https://api.github.com/users/CSomerville/events{/privacy}","received_events_url":"https://api.github.com/users/CSomerville/received_events","type":"User","site_admin":false},"created_at":"2016-12-14T23:42:04Z","updated_at":"2016-12-14T23:42:04Z","body":"Nevermind about bypassing `Error.captureStackTrace()`, looks like it is as simple as enabling `q.longStackSupport`."}}
{"actor":{"display_login":"CSomerville"}}