{"action":"created","issue":{"url":"https://api.github.com/repos/sindresorhus/ava/issues/771","repository_url":"https://api.github.com/repos/sindresorhus/ava","labels_url":"https://api.github.com/repos/sindresorhus/ava/issues/771/labels{/name}","comments_url":"https://api.github.com/repos/sindresorhus/ava/issues/771/comments","events_url":"https://api.github.com/repos/sindresorhus/ava/issues/771/events","html_url":"https://github.com/sindresorhus/ava/issues/771","id":149317156,"number":771,"title":"Uncaught exception helper","user":{"login":"jamestalmage","id":4082216,"avatar_url":"https://avatars.githubusercontent.com/u/4082216?v=3","gravatar_id":"","url":"https://api.github.com/users/jamestalmage","html_url":"https://github.com/jamestalmage","followers_url":"https://api.github.com/users/jamestalmage/followers","following_url":"https://api.github.com/users/jamestalmage/following{/other_user}","gists_url":"https://api.github.com/users/jamestalmage/gists{/gist_id}","starred_url":"https://api.github.com/users/jamestalmage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamestalmage/subscriptions","organizations_url":"https://api.github.com/users/jamestalmage/orgs","repos_url":"https://api.github.com/users/jamestalmage/repos","events_url":"https://api.github.com/users/jamestalmage/events{/privacy}","received_events_url":"https://api.github.com/users/jamestalmage/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/sindresorhus/ava/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/sindresorhus/ava/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2016-04-19T01:10:46Z","updated_at":"2016-04-24T23:31:44Z","closed_at":null,"body":"As an alternative (or possibly in addition) to using domains to try and track the source of an uncaught exception, what if we used a babel plugin to wrap function declarations?\r\n\r\n```js\r\ntest.cb(t => {\r\n  setTimeout(() => {\r\n     assert(something); // a failing assertion thrown here doesn't get grouped with the correct test.\r\n     t.end();\r\n  });\r\n});\r\n```\r\n\r\nBecomes:\r\n\r\n```js\r\ntest(t => {\r\n  setTimeout(t.__wrapFn(() => {\r\n    assert(something);\r\n    t.end();\r\n  });\r\n});\r\n```\r\n\r\n`t.__wrapFn` would just mark the error with the associated test before letting it continue to bubble up:\r\n\r\n```js\r\nt.prototype.__wrapFn = function (fn) {\r\n  var self = this;\r\n  return function () {\r\n    try {\r\n      return fn.apply(this, arguments);\r\n    } catch (e) {\r\n      e.__associatedAvaTest = self;\r\n      throw e;\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nOur `uncaughtException` handler could then detect the special property and fail the specific associated test instead of killing the whole process."},"comment":{"url":"https://api.github.com/repos/sindresorhus/ava/issues/comments/214065628","html_url":"https://github.com/sindresorhus/ava/issues/771#issuecomment-214065628","issue_url":"https://api.github.com/repos/sindresorhus/ava/issues/771","id":214065628,"user":{"login":"jamestalmage","id":4082216,"avatar_url":"https://avatars.githubusercontent.com/u/4082216?v=3","gravatar_id":"","url":"https://api.github.com/users/jamestalmage","html_url":"https://github.com/jamestalmage","followers_url":"https://api.github.com/users/jamestalmage/followers","following_url":"https://api.github.com/users/jamestalmage/following{/other_user}","gists_url":"https://api.github.com/users/jamestalmage/gists{/gist_id}","starred_url":"https://api.github.com/users/jamestalmage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamestalmage/subscriptions","organizations_url":"https://api.github.com/users/jamestalmage/orgs","repos_url":"https://api.github.com/users/jamestalmage/repos","events_url":"https://api.github.com/users/jamestalmage/events{/privacy}","received_events_url":"https://api.github.com/users/jamestalmage/received_events","type":"User","site_admin":false},"created_at":"2016-04-24T23:31:44Z","updated_at":"2016-04-24T23:31:44Z","body":"Oh also make sure you start with `astexplorer`. It's a great resource to get started."}}