Took me a while to find a bug in my sourceNodes code, because errors are ignored in createRemoteFileNode inside processRemoteNode function.
I kept getting null back from createRemoteFileNode. So after some digging, I put a console.log directly into gatsby-source-filesystem inside my node_modules and see the error
error TypeError: createNodeId is not a function
at /home/bojan/www/instaset/website/node_modules/gatsby-source-filesystem/create-file-node.js:61:11
at Generator.next (<anonymous>)
at step (/home/bojan/www/instaset/website/node_modules/@babel/runtime/helpers/asyncToGenerator.js:12:30)
at _next (/home/bojan/www/instaset/website/node_modules/@babel/runtime/helpers/asyncToGenerator.js:27:9)
at run (/home/bojan/www/instaset/website/node_modules/core-js/library/modules/es6.promise.js:75:22)
at /home/bojan/www/instaset/website/node_modules/core-js/library/modules/es6.promise.js:92:30
at flush (/home/bojan/www/instaset/website/node_modules/core-js/library/modules/_microtask.js:18:9)
at process._tickCallback (internal/process/next_tick.js:61:11)
Maybe we can do something about that?
Is this for a custom source plug-in?
Yes.
This is probably what you need https://next.gatsbyjs.org/docs/migrating-from-v1-to-v2/#createremotefilenode
Hmm ... I didn't present this problem in a correct way :) I know about the new createNodeId parameter. But I made a mistake and imported it from actions instead of props
exports.sourceNodes = async ({ actions, store, cache }) => {
const { createNode, createNodeId } = actions
// ...
}
createRemoteFileNode kept returning null, and there was no error, because it is ignored. Is this intentional?
I already solved my problem, you can close this issue if you wish. Just wanted to point this out ;)
This is the right way to destructure props:
exports.sourceNodes = async ({ actions, createNodeId, store, cache }) => {
const { createNode } = actions
// ...
}
Yeah, validating the options and throwing an error sounds like a great plan. Would you like to PR that?
Sure. I'm rather busy ATM, but will try to find some time to look at the situation ;)
@KyleAMathews I looked at the code a little bit. The error is ignored in the processRemoteNode function:
async function processRemoteNode({
url,
store,
cache,
createNode,
auth = {},
createNodeId,
}) {
try {
// ...
} catch (err) {
// ignore <<<<<<<<<<<<<<<< HERE
}
return null
}
We could throw err there, but then what's the point of even having a try catch block? Or did you mean that we should throw in options are invalid?
Are there any examples on how to validate the options, or should we simply check for the presence of all required parameters such as createNodeId function for example?
I just ran into this as well because of some 404s. The silent failure made this pretty hard to debug when using gatsby-source-drupal.
Most helpful comment
Hmm ... I didn't present this problem in a correct way :) I know about the new
createNodeIdparameter. But I made a mistake and imported it fromactionsinstead ofpropscreateRemoteFileNodekept returningnull, and there was no error, because it is ignored. Is this intentional?I already solved my problem, you can close this issue if you wish. Just wanted to point this out ;)
This is the right way to destructure props: