Skip to content

fix(gatsby-source-filesystem): createRemoteFileNode rejects promise instead resolving on failure - #12348

Merged
wardpeet merged 1 commit into
gatsbyjs:masterfrom
antoinerousseau:master
May 15, 2019
Merged

fix(gatsby-source-filesystem): createRemoteFileNode rejects promise instead resolving on failure#12348
wardpeet merged 1 commit into
gatsbyjs:masterfrom
antoinerousseau:master

Conversation

@antoinerousseau

@antoinerousseau antoinerousseau commented Mar 6, 2019

Copy link
Copy Markdown
Contributor

Description

When createRemoteFileNode fails to download a remote file (e.g. 404), it returns a rejected Promise, with the error containing the failing URL and the error message, instead of resolving with undefined and outputting the error using console.log.
Additionally, it also returns a rejected Promise if the requested URL is invalid, instead of resolving with undefined.

This is a breaking change: we should inform users that they should catch possible rejections.

Related Issues

This PR fixes #12280

@antoinerousseau

Copy link
Copy Markdown
Contributor Author

@DSchau could you review this please?

@pieh

pieh commented Mar 26, 2019

Copy link
Copy Markdown
Contributor

This generally seems very sensible (we really should do that from the start), but it does change behaviour: consumers of createRemoteFileNode will need to be changed from checking if function returned promise resolving to null/undefined to catching errors, so I would consider this a breaking change.

@leonfs

leonfs commented May 8, 2019

Copy link
Copy Markdown

@DSchau - Is there a possibility to get this PR merged soon?

@wardpeet wardpeet added the breaking change If implemented, this proposed work would break functionality for older versions of Gatsby label May 8, 2019
@wardpeet

wardpeet commented May 8, 2019

Copy link
Copy Markdown
Contributor

it's probably best to wait for gatsby v3 to actually merge this one as it's a breaking change in a widely used package. Technically we could bump it's major to vesion 3 but unsure what @pieh thinks

@leonfs

leonfs commented May 8, 2019

Copy link
Copy Markdown

Thanks, @wardpeet - I dissent with your opinion about being a breaking change, I think it is a bug more than a change in the contract. The current implementation returns a promise, and it is expected that as such it can throw. Most packages I've seen using it have a try/catch around it, though the catch will never run because it always resolves.

We had a bug in our platform because we didn't get the failure, and the build continued as if nothing happened.

@roylines

roylines commented May 8, 2019

Copy link
Copy Markdown

Totally agree. Caught us out big time. Would be awesome to see this merged.

@wardpeet

Copy link
Copy Markdown
Contributor

discussing this with the team if we will bring this one in or not and break things.

@leonfs

leonfs commented May 14, 2019

Copy link
Copy Markdown

Thanks @wardpeet - There is always an option to not make it a breaking change, an optional parameter could be passed in (rejectOnError) defaulted to false. That way current consumers don't get the change in expected behaviours. Then on v3 make the breaking change and remove the optional parameter.

@KyleAMathews

Copy link
Copy Markdown
Contributor

Yeah, let's merge this 👍

@wardpeet wardpeet removed the breaking change If implemented, this proposed work would break functionality for older versions of Gatsby label May 15, 2019

@wardpeet wardpeet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's ship this!

@wardpeet wardpeet changed the title gatsby-source-filesystem#createRemoteFileNode returns a rejected promise if it fails fix(gatsby-source-filesystem): createRemoteFileNode rejects promise instead resolving on failure May 15, 2019
@wardpeet
wardpeet merged commit c2c5cea into gatsbyjs:master May 15, 2019
@gatsbot

gatsbot Bot commented May 15, 2019

Copy link
Copy Markdown

Holy buckets, @antoinerousseau — we just merged your PR to Gatsby! 💪💜

Gatsby is built by awesome people like you. Let us say “thanks” in two ways:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. We’ve got Gatsby t-shirts, stickers, hats, scrunchies, and much more. (You can also unlock even more free swag with 5 contributions — wink wink nudge nudge.) See gatsby.dev/swag for details.
  2. We just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. Accept the invite by visiting https://github.com/orgs/gatsbyjs/invitation. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

If there’s anything we can do to help, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’.

Thanks again!

@wardpeet

Copy link
Copy Markdown
Contributor
Successfully published:
 - gatsby-source-filesystem@2.0.35

@leonfs

leonfs commented May 15, 2019

Copy link
Copy Markdown

Thanks @wardpeet and @KyleAMathews

@antoinerousseau

Copy link
Copy Markdown
Contributor Author

I'm having an UNHANDLED REJECTION when fetching URLs having a 404 error, even when I catch the createRemoteFileNode Promise... any clue?

@wardpeet

Copy link
Copy Markdown
Contributor

Is it possible to share a code snippet?

@antoinerousseau

Copy link
Copy Markdown
Contributor Author

@wardpeet here you go!
https://github.com/antoinerousseau/gatsby-bug-mvce
Should I open an issue maybe? Or did I miss something?

@wardpeet

Copy link
Copy Markdown
Contributor

yes please do :)

@antoinerousseau

Copy link
Copy Markdown
Contributor Author

@wardpeet opened #14178

mwfrost pushed a commit to mwfrost/gatsby that referenced this pull request Apr 20, 2023
raffishquartan pushed a commit to raffishquartan/gatsby that referenced this pull request Apr 28, 2026
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

Successfully merging this pull request may close these issues.

[gatsby-source-filesystem] why createRemoteFileNode failing still resolves the promise?

6 participants