Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Cannot convert object to primitive value in console.js #1750

Closed
jordan-sf opened this issue Sep 7, 2018 · 2 comments
Closed
Assignees
Labels
AREA: client STATE: Auto-locked Issues that were automatically locked by the Lock bot TYPE: bug
Milestone

Comments

@jordan-sf
Copy link

jordan-sf commented Sep 7, 2018

const line = arrayMap.call(args, String).join(' ');

Are you requesting a feature or reporting a bug?

Bug

What is the current behavior?

On this line, when trying to console.log/.error/etc an array containing a "derived" object, an exception is thrown:

Uncaught TypeError: Cannot convert object to primitive value
    at String (<anonymous>)
    at Array.map (native)

I'm using AngularJS's http service, and with a (failed) http response, the return value of response.header() in the following example code has a header that looks like an Object. However, its .__proto__ property is missing, and so it doesn't have the .toString() method, causing the above error.

$http(options)
.then(function successCallback(response) {
    if (!response) {
        deferred.reject(response);
    } else {
        console.debug('Success call URL', options.url, 'Status:', response.status, 'Data:', response.data, 'Headers:', response.headers(), 'Config:', response.config)
        deferred.resolve(response.data);
    }
}, function errorCallback(response) {
    console.error('Failed call URL', options.url, 'Status:', response.status, 'Error:', response.data, 'Headers:', response.headers(), 'Config:', response.config)
    deferred.reject(response);
});

What is the expected behavior?

The proxied console.* methods are able to work as expected without throwing an exception. For a comparison, instead of the Array.prototype.map.call line in the code below, simply run console.log(args).

How would you reproduce the current behavior (if this is a bug)?

let header1 = {"Date": Date()};
let header2 = {"other_data": "some data"};
let header2.__proto__ = null;
let args = [header1, header2];
Array.prototype.map.call(args, String);

Provide the test code and the tested page URL (if applicable)

Tested page URL:

Test code

Specify your

  • operating system: Windows 10
  • testcafe-hammerhead version: 14.2.7
  • node.js version: 8.11.3
@miherlosev
Copy link
Contributor

Hi @jordan-sf

Thank you for the detailed bug description. We will fix it during the next development sprint.

@miherlosev miherlosev modified the milestones: Sprint #18, Sprint #19 Oct 1, 2018
AndreyBelym pushed a commit to AndreyBelym/testcafe-hammerhead that referenced this issue Feb 28, 2019
…console.js` (close DevExpress#1750) (DevExpress#1778)

* fix `Uncaught TypeError: Cannot convert object to primitive value in console.js` (close DevExpress#1750)

* requested changes: simplify
@lock
Copy link

lock bot commented Mar 28, 2019

This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.

@lock lock bot added the STATE: Auto-locked Issues that were automatically locked by the Lock bot label Mar 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
AREA: client STATE: Auto-locked Issues that were automatically locked by the Lock bot TYPE: bug
Projects
None yet
Development

No branches or pull requests

3 participants