{"action":"created","issue":{"url":"https://api.github.com/repos/petkaantonov/bluebird/issues/1146","repository_url":"https://api.github.com/repos/petkaantonov/bluebird","labels_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/1146/labels{/name}","comments_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/1146/comments","events_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/1146/events","html_url":"https://github.com/petkaantonov/bluebird/issues/1146","id":162339411,"number":1146,"title":"Invalid `rejected with a non-error` warning","user":{"login":"vitaly-t","id":5108906,"avatar_url":"https://avatars.githubusercontent.com/u/5108906?v=3","gravatar_id":"","url":"https://api.github.com/users/vitaly-t","html_url":"https://github.com/vitaly-t","followers_url":"https://api.github.com/users/vitaly-t/followers","following_url":"https://api.github.com/users/vitaly-t/following{/other_user}","gists_url":"https://api.github.com/users/vitaly-t/gists{/gist_id}","starred_url":"https://api.github.com/users/vitaly-t/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vitaly-t/subscriptions","organizations_url":"https://api.github.com/users/vitaly-t/orgs","repos_url":"https://api.github.com/users/vitaly-t/repos","events_url":"https://api.github.com/users/vitaly-t/events{/privacy}","received_events_url":"https://api.github.com/users/vitaly-t/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":13,"created_at":"2016-06-26T18:07:18Z","updated_at":"2016-06-28T01:01:24Z","closed_at":"2016-06-26T18:10:15Z","body":"When we set a message in out custom error object based on some non-string data, Bluebird displays `Warning: a promise was rejected with a non-error: [object Object]`, which is clearly a mistake.\r\n\r\nHere's complete example:\r\n\r\n```js\r\n'use strict';\r\n\r\nvar util = require('util');\r\nvar promise = require('bluebird');\r\n\r\nfunction CustomError(data) {\r\n    this.message = data;\r\n    Error.captureStackTrace(this, CustomError);\r\n}\r\n\r\nutil.inherits(CustomError, Error);\r\nCustomError.prototype.name = 'CustomError';\r\n\r\npromise.reject(new CustomError([]))\r\n    .catch(error=> {\r\n        console.log(error);\r\n    });\r\n```\r\n\r\nThis should not produce that warning, but it does.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/petkaantonov/bluebird/issues/comments/228920288","html_url":"https://github.com/petkaantonov/bluebird/issues/1146#issuecomment-228920288","issue_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/1146","id":228920288,"user":{"login":"spion","id":502412,"avatar_url":"https://avatars.githubusercontent.com/u/502412?v=3","gravatar_id":"","url":"https://api.github.com/users/spion","html_url":"https://github.com/spion","followers_url":"https://api.github.com/users/spion/followers","following_url":"https://api.github.com/users/spion/following{/other_user}","gists_url":"https://api.github.com/users/spion/gists{/gist_id}","starred_url":"https://api.github.com/users/spion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spion/subscriptions","organizations_url":"https://api.github.com/users/spion/orgs","repos_url":"https://api.github.com/users/spion/repos","events_url":"https://api.github.com/users/spion/events{/privacy}","received_events_url":"https://api.github.com/users/spion/received_events","type":"User","site_admin":false},"created_at":"2016-06-28T01:01:24Z","updated_at":"2016-06-28T01:01:24Z","body":"Here, let me try and explain it again.\r\n\r\n1. Bluebird calls `var trace = util.ensureErrorObject(error)`. It works like this\r\n\r\n```js\r\nfunction ensureErrorObject(error) {\r\n  if (isReallyError(error)) return error;\r\n  else return wrapIntoActualError(error);\r\n}\r\n```\r\n\r\nBluebird does a reference comparison to see if ensure returned the same object\r\n\r\n```js\r\nif (trace === error)\r\n```\r\n\r\nThis will only be true if the first branch was triggered i.e. `if (isReallyError(error)) return error;`\r\n\r\nThe reason for this magic is that the cost of a reference comparison is much lower than checking the error object all over again.\r\n\r\nMy suggestion would be to make a minimal test case - that should make it easier to figure it out."}}
{"actor":{"display_login":"spion"}}