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

Fetch errors do not result in a promise rejection #23

Open
jaxoncreed opened this issue May 1, 2019 · 8 comments

Comments

Projects
None yet
4 participants
@jaxoncreed
Copy link

commented May 1, 2019

When doing an asynchronous request, try/catch statements should properly catch errors, but they do not.

Example:

When running this code via a web-browswer on localhost, Tim's pod disallows requests coming from the unregistered localhost app. This is all fine, but the resulting error it triggers cannot be caught.

    try {
      const timName = (await data['http://www.w3.org/People/Berners-Lee/card#i'].vcard_fn).value;
      console.log(timName);
    } catch(err) {
      console.log('this should be caught')
      console.error(err);
    }

This yields Uncaught (in promise) TypeError: Failed to fetch

The same result will happen if I try to retrieve an improperly formatted ttl file

@RubenVerborgh

This comment has been minimized.

Copy link
Member

commented May 1, 2019

@rubensworks

This comment has been minimized.

Copy link
Member

commented May 2, 2019

Comunica is probably the root cause of this problem, see comunica/comunica#381

@RubenVerborgh

This comment has been minimized.

Copy link
Member

commented May 5, 2019

Root cause is apparently RubenVerborgh/LDflex-Comunica#13.

@jaxoncreed Could you check how the above works for you with the proposed fix there?

RubenVerborgh added a commit to rubensworks/LDflex-Comunica that referenced this issue May 5, 2019

@RubenVerborgh

This comment has been minimized.

Copy link
Member

commented May 5, 2019

After quick testing with the original code:

  • Firefox yields TypeError: "undefined has no properties"
  • Chrome yields Uncaught (in promise) TypeError: Failed to fetch

So that discrepancy is also a problem.

@RubenVerborgh

This comment has been minimized.

Copy link
Member

commented May 5, 2019

After RubenVerborgh/LDflex-Comunica#13, also two different behaviors:

  • Firefox yields TypeError: "undefined has no properties"
  • Chrome never resolves or rejects the promise

Especially the second thing is a problem. If Chrome does not return anything to us on failure, we'd need to resolve to a timeout.

@RubenVerborgh RubenVerborgh added the bug label May 5, 2019

@RubenVerborgh RubenVerborgh changed the title Try/catch does not catch asynchronous errors Fetch errors do not result in a promise rejection May 5, 2019

@rubensworks

This comment has been minimized.

Copy link
Member

commented May 6, 2019

I just tested the example above in Chrome 72.0.3626.121, and err is properly caught every time.

However, when I test with an unknown domain, no error is caught at all, but the promise rejects, and only the very first time:
Screen Shot 2019-05-06 at 08 30 21

@RubenVerborgh Are you aware of any caching going on in LDflex?
Comunica only caches RDF sources with 200 status codes (unless there's a bug somewhere).

@akashdeep-singh

This comment has been minimized.

Copy link

commented Jul 10, 2019

Has there been any update on this? I've been getting it on Firefox and Chrome for 403 errors.
This is the line it originates from:
https://github.com/comunica/comunica/blob/85722d73f1109dcf6042b69e4893b59c84cf3096/packages/actor-rdf-dereference-http-parse/lib/ActorRdfDereferenceHttpParseBase.ts#L59

@RubenVerborgh

This comment has been minimized.

Copy link
Member

commented Jul 16, 2019

The same problem is also present in Node, where the following code stops:

const ruben = data['https://ruben.verborgh.org/profile/#me'];
showPerson(ruben)

async function showPerson(person) {
  console.log(`This person is ${await person.label}`);
  console.log(`${await person.givenName} is friends with:`);
  for await (const myFriend of person.friends) {
    console.log(`- ${myFriend}`);
    for await (const otherFriend of data[`${myFriend}`].friends)
      console.log(`  - ${otherFriend}`);
  }
}

The error is

(node:14373) UnhandledPromiseRejectionWarning: Error: Could not retrieve http://www.informatik.uni-leipzig.de/~auer/foaf.rdf (404)
    at ActorRdfDereferenceHttpParse.run (/Users/ruben/Documents/UGent/Solid/solid-query-ldflex/node_modules/@comunica/actor-rdf-dereference-http-parse/lib/ActorRdfDereferenceHttpParse.js:37:19)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:14373) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1099)
(node:14373) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.