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

ES6 diffString Cannot read properties of null (reading 'key') #71

Closed
justinhessdev opened this issue Dec 21, 2021 · 3 comments
Closed

Comments

@justinhessdev
Copy link

justinhessdev commented Dec 21, 2021

diffString is erroring out when it comes to an empty array of objects:

  const patch = diffString(
    { 
      services: [],
    },
    {
      services: [{ service_code: '123' }],
    }
  );
index.js:54 TypeError: Cannot read properties of null (reading 'key')
    at JsonDiff.scalarize (index.js:103)
    at JsonDiff.arrayDiff (index.js:144)
    at JsonDiff.diff (index.js:289)
    at JsonDiff.objectDiff (index.js:39)
    at JsonDiff.diff (index.js:286)
    at diff (index.js:315)
    at diffString (index.js:319)
    at DiffTest (index.stories.js:54)
    at finalStoryFn (story_store.js:568)
    at hooks.js:182

I need to compare many large objects that I shouldn't mutate. Some will have empty arrays of objects which will cause the app to crash.

Would it be possible to fix this?

** Update: this was not working on version 0.6.1
apparently there was a fix earlier today -- working on 0.6.3

@ivan-015
Copy link

This is happening to me in version 0.7.3, is there a fix for this?

@ewoudenberg
Copy link
Collaborator

@ivan-015 I cannot repro

$ cd bin
$ node
Welcome to Node.js v16.13.0.
Type ".help" for more information.
> require('../lib/index').diffString(    { 
...       services: [],
...     },
...     {
.....       services: [{ service_code: '123' }],
.....     }
...   );
' {\n' +
  '   services: [\n' +
  '\x1B[32m+    {\x1B[39m\n' +
  '\x1B[32m+      service_code: "123"\x1B[39m\n' +
  '\x1B[32m+    }\x1B[39m\n' +
  '   ]\n' +
  ' }\n'

@ivan-015
Copy link

@ewoudenberg thanks for your prompt reply. This was my mistake. I had this package installed in a Docker container and it was caching the package's old version. After running docker with no cache, the error went away. Thanks again!

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

No branches or pull requests

3 participants