Skip to content
This repository has been archived by the owner on May 14, 2020. It is now read-only.

Error objects cannot be expanded + Fix for #20 #22

Closed
skleeschulte opened this issue Jan 8, 2016 · 5 comments
Closed

Error objects cannot be expanded + Fix for #20 #22

skleeschulte opened this issue Jan 8, 2016 · 5 comments

Comments

@skleeschulte
Copy link

Error objects in the state tree cannot be expanded. Thats because iterating with for...in and hasOwnProperty doesn't work here. However this should easily be fixed by adding this before line 30 in JSONObjectNode.js:

if (data instanceof Error) {
    data = Object.getOwnPropertyNames(data).reduce(function (errorObj, prop) {
        errorObj[prop] = data[prop];
        return errorObj;
    }, {});
}

In addition, to solve Objects without prototype chain are broken #20 , line 32 in JSONObjectNode.js could be changed to:

if (Object.getPrototypeOf(data) === null || data.hasOwnProperty(key)) {

(IMHO thats better than PR Fixes #20, expanding of objects without prototype #21.)

I would create a pull request, but I cannot test this, because I cannot build the package. (I cloned it from github, but get lot's of errors on npm install, npm build and npm run lint. Even after fixing npm install and npm build (by removing all the carets from the dependency versions in package.json and installing [email protected]), with npm build the output in lib looks different from what I get from npm install react-json-tree.)

But I'm sure someone can do it. :)

@chibicode
Copy link
Contributor

Thanks! Closed by #23

@skleeschulte
Copy link
Author

PR #23 only fixes issue #20 by adding if (Object.getPrototypeOf(data) === null || data.hasOwnProperty(key)) {. The main thing this issue is about is that errors cannot be extended, which is because the for...in loop doesn't iterate over Error instance properties.

@chibicode chibicode reopened this Jan 12, 2016
@chibicode
Copy link
Contributor

@skleeschulte sorry I read it wrong, reopened this issue

@alexkuz
Copy link
Owner

alexkuz commented Apr 17, 2016

Should be fixed by dadf3d3

@alexkuz alexkuz closed this as completed Apr 17, 2016
@dorian-marchal
Copy link

dorian-marchal commented Jan 30, 2018

Looks like the issue is still there (in redux-devtools, at least, which uses v0.11).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants