cloudinary-community / cloudinary-community/gatsby-transformer-cloudinary

Cannot convert undefined or null to object - when some image nodes are null

Open
#68 5 comments 0 reactions 0 assignees View on GitHub
needs more info
Dominant language
JavaScript
Stars
68
Forks
28
PR merge metrics
No merged PRs in 30d

Description

The plugin is functioning and we get graphQL nodes created from the Cloudinary images, however we get the following error:

```
error "gatsby-transformer-cloudinary" threw an error while running the onCreateNode lifecycle:

Cannot convert undefined or null to object

53 | const currentNode = basePath === '' ? node : get(node, basePath);
54 |
> 55 | const directAssetDataPaths = Object.keys(currentNode)
| ^
56 | .filter(key => {
57 | return currentNode[key] && currentNode[key].cloudinaryAssetData === true;
58 | })

TypeError: Cannot convert undefined or null to object

- Function.keys

- create-asset-nodes-from-data.js:55 getAssetDataPaths
[mysite]/[gatsby-transformer-cloudinary]/gatsby-node/create-asset-nodes-from-data.js:55:39
...
```

This occurs in develop and build, in develop it will get past this error, but build fails.

We are adding an object for cloudinary with all the applicable data, but due to our database structure this object is occasionally null. For instance:
```
mediaItems: [
{
...,
"cloudinary": {
"cloudName": "mycloudname",
"orginalHeight: 2250,
"cloudinaryAssetData": true,
...
}
},
"cloudinary": null
]
```

Currently the situation is that the plugin appears to be working ok - the above structure is how it looks before the plugin is working. These get replaced with the fixed/fluid image graphQL node and the plugin appears to be working fine. But it still produces the error above, which of course fails the build.

It would be good if this isn't an error! A warning at most, so long as it finds at least some useable objects that would seem to be sufficient. Unfortunately making changes to our DB is a little difficult, there may be a way round this with gatsby-node.js, but it would be good to see if there's a fix perhaps.

Contributor guide

Open the contributing guide

Research direction

Start in gatsby-node/create-asset-nodes-from-data.js at getAssetDataPaths, especially the Object.keys call on line 55. Reproduce the reported develop and build case with an image node whose cloudinary value is null, then verify that usable Cloudinary objects are still processed without the build failing.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.