{"action":"created","issue":{"url":"https://api.github.com/repos/tj/co/issues/188","labels_url":"https://api.github.com/repos/tj/co/issues/188/labels{/name}","comments_url":"https://api.github.com/repos/tj/co/issues/188/comments","events_url":"https://api.github.com/repos/tj/co/issues/188/events","html_url":"https://github.com/tj/co/issues/188","id":54323709,"number":188,"title":"Consistent stack traces","user":{"login":"madbence","id":296735,"avatar_url":"https://avatars.githubusercontent.com/u/296735?v=3","gravatar_id":"","url":"https://api.github.com/users/madbence","html_url":"https://github.com/madbence","followers_url":"https://api.github.com/users/madbence/followers","following_url":"https://api.github.com/users/madbence/following{/other_user}","gists_url":"https://api.github.com/users/madbence/gists{/gist_id}","starred_url":"https://api.github.com/users/madbence/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/madbence/subscriptions","organizations_url":"https://api.github.com/users/madbence/orgs","repos_url":"https://api.github.com/users/madbence/repos","events_url":"https://api.github.com/users/madbence/events{/privacy}","received_events_url":"https://api.github.com/users/madbence/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-01-14T13:49:04Z","updated_at":"2015-01-18T22:49:05Z","closed_at":null,"body":"My problem is that if my `Error` is not created in the context of the generator, the stack trace is missing:\r\n\r\n```js\r\nvar co = require('co');\r\n\r\nfunction* a() {\r\n  yield* b();\r\n}\r\n\r\nfunction* b() {\r\n  yield new Promise(function(resolve, reject) {\r\n    setTimeout(function() {\r\n      reject(new Error());\r\n    }, 1000);\r\n  });\r\n}\r\n\r\nco(function* () {\r\n  try {\r\n    yield* a();\r\n  } catch(err) {\r\n    console.error(err.stack);\r\n  }\r\n});\r\n```\r\n\r\n```\r\nError\r\n    at null._onTimeout (...)\r\n    at Timer.listOnTimeout (...)\r\n```\r\n\r\nStack trace is just fine, if I throw in the generator:\r\n\r\n```js\r\nvar co = require('co');\r\n\r\nfunction* a() {\r\n  yield* b();\r\n}\r\n\r\nfunction* b() {\r\n  yield new Promise(function(resolve, reject) {\r\n    setTimeout(function() {\r\n      resolve();\r\n    }, 1000);\r\n  });\r\n  throw new Error();\r\n}\r\n\r\nco(function* () {\r\n  try {\r\n    yield* a();\r\n  } catch(err) {\r\n    console.error(err.stack);\r\n  }\r\n});\r\n```\r\n\r\n```\r\nError\r\n    at b (...)\r\n    at GeneratorFunctionPrototype.next (...)\r\n    at a (...)\r\n    at GeneratorFunctionPrototype.next (...)\r\n    at ...\r\n    at GeneratorFunctionPrototype.next (...)\r\n    at onFulfilled (...)\r\n```\r\n\r\nI perfectly understand that this is the correct behavior (the `setTimeout`s callback has absolutely no idea that the computation was suspended), but it is really annoying. Is there any other way to fix this other than wrapping every `Promise` in a try-catch, and wrapping the original `Error` with a new one?\r\n\r\n```js\r\ntry {\r\n  yield new Promise(function(resolve, reject) {\r\n    setTimeout(function() {\r\n      reject(new Error())\r\n    }, 1000);\r\n  });\r\n} catch(e) {\r\n  var err = new Error(e.message);\r\n  err.original = e;\r\n  throw err;\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/tj/co/issues/comments/70430384","html_url":"https://github.com/tj/co/issues/188#issuecomment-70430384","issue_url":"https://api.github.com/repos/tj/co/issues/188","id":70430384,"user":{"login":"jonathanong","id":643505,"avatar_url":"https://avatars.githubusercontent.com/u/643505?v=3","gravatar_id":"","url":"https://api.github.com/users/jonathanong","html_url":"https://github.com/jonathanong","followers_url":"https://api.github.com/users/jonathanong/followers","following_url":"https://api.github.com/users/jonathanong/following{/other_user}","gists_url":"https://api.github.com/users/jonathanong/gists{/gist_id}","starred_url":"https://api.github.com/users/jonathanong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonathanong/subscriptions","organizations_url":"https://api.github.com/users/jonathanong/orgs","repos_url":"https://api.github.com/users/jonathanong/repos","events_url":"https://api.github.com/users/jonathanong/events{/privacy}","received_events_url":"https://api.github.com/users/jonathanong/received_events","type":"User","site_admin":false},"created_at":"2015-01-18T22:49:05Z","updated_at":"2015-01-18T22:49:05Z","body":"PR welcomed, but i'm not a big fan of manipulating stack traces"}}