{"action":"opened","issue":{"url":"https://api.github.com/repos/apifytech/apify-js/issues/243","repository_url":"https://api.github.com/repos/apifytech/apify-js","labels_url":"https://api.github.com/repos/apifytech/apify-js/issues/243/labels{/name}","comments_url":"https://api.github.com/repos/apifytech/apify-js/issues/243/comments","events_url":"https://api.github.com/repos/apifytech/apify-js/issues/243/events","html_url":"https://github.com/apifytech/apify-js/issues/243","id":384545581,"node_id":"MDU6SXNzdWUzODQ1NDU1ODE=","number":243,"title":"Elaborate stringify failure error message","user":{"login":"jonathanstanley","id":2755958,"node_id":"MDQ6VXNlcjI3NTU5NTg=","avatar_url":"https://avatars1.githubusercontent.com/u/2755958?v=4","gravatar_id":"","url":"https://api.github.com/users/jonathanstanley","html_url":"https://github.com/jonathanstanley","followers_url":"https://api.github.com/users/jonathanstanley/followers","following_url":"https://api.github.com/users/jonathanstanley/following{/other_user}","gists_url":"https://api.github.com/users/jonathanstanley/gists{/gist_id}","starred_url":"https://api.github.com/users/jonathanstanley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonathanstanley/subscriptions","organizations_url":"https://api.github.com/users/jonathanstanley/orgs","repos_url":"https://api.github.com/users/jonathanstanley/repos","events_url":"https://api.github.com/users/jonathanstanley/events{/privacy}","received_events_url":"https://api.github.com/users/jonathanstanley/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-11-26T22:53:41Z","updated_at":"2018-11-26T22:53:41Z","closed_at":null,"author_association":"NONE","body":"I noticed the following error:\r\n`The \"value\" parameter cannot be stringified to JSON.`\r\n\r\nIt took me hours to fully understand this [JSON.stringify error notice](https://github.com/apifytech/apify-js/blob/master/src/key_value_store.js#L88).  I wasn't sure what to do.  I spent a lot of time trying to convert to buffer, check if my code had an error, etc.  What I did not know is that we JSON.stringify() cannot handle circular objects.  For example, [DOM are often circular](https://stackoverflow.com/a/8106797). \r\n [Mozilla explains this very well in their docs.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Issue_with_JSON.stringify()_when_serializing_circular_references)  An easy way to resolve this is to use [json-cycle](https://www.npmjs.com/package/json-cycle).  It would have been very helpful if the error message said something like this\r\n\r\n`throw new Error('Unable to complete JSON.stringify().  Maybe decycle your object before storing.');`\r\n\r\nIt would also be great if you updated the [key-value store documentation](https://github.com/apifytech/apify-js/blob/master/docs/api/KeyValueStore.md#keyvaluestoresetvaluekey-value-options--promise) to somethings like this:\r\n\r\n> Record data, which can be one of the following values:\r\n> If null, the record in the key-value store is deleted.\r\n> If no options.contentType is specified, value can be any JavaScript object and it will be stringified to JSON.\r\n> If options.contentType is specified, value is considered raw data and it must be either a String or Buffer.\r\n> For any other value an error will be thrown.  JSON.stringify() cannot resolve circular objects.  Maybe use https://www.npmjs.com/package/json-cycle to decycle your object before storage to get around this."}}
{"actor":{"display_login":"jonathanstanley"}}