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

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

Merged
merged 1 commit into from
May 15, 2019

Conversation

antoinerousseau
Copy link
Contributor

@antoinerousseau antoinerousseau commented Mar 6, 2019

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
Contributor Author

@DSchau could you review this please?

@pieh
Copy link
Contributor

pieh commented Mar 26, 2019

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
Copy link

leonfs commented May 8, 2019

@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
Copy link
Contributor

wardpeet commented May 8, 2019

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
Copy link

leonfs commented May 8, 2019

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
Copy link

roylines commented May 8, 2019

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

@wardpeet
Copy link
Contributor

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

@leonfs
Copy link

leonfs commented May 14, 2019

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
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
Copy link
Contributor

@wardpeet wardpeet left a comment

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
Copy link

gatsbot bot commented May 15, 2019

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
Contributor

Successfully published:
 - gatsby-source-filesystem@2.0.35

@leonfs
Copy link

leonfs commented May 15, 2019

Thanks @wardpeet and @KyleAMathews

@antoinerousseau
Copy link
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
Contributor

Is it possible to share a code snippet?

@antoinerousseau
Copy link
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
Contributor

yes please do :)

@antoinerousseau
Copy link
Contributor Author

@wardpeet opened #14178

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