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

Closed
jaxoncreed opened this issue May 1, 2019 · 11 comments · Fixed by LDflex/LDflex-Comunica#13
Closed

Fetch errors do not result in a promise rejection #23

jaxoncreed opened this issue May 1, 2019 · 11 comments · Fixed by LDflex/LDflex-Comunica#13
Assignees
Labels
bug Something isn't working

Comments

@jaxoncreed
Copy link

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

RubenVerborgh commented May 1, 2019 via email

@rubensworks
Copy link
Contributor

rubensworks commented May 2, 2019

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

@RubenVerborgh
Copy link
Member

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

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

RubenVerborgh pushed a commit to rubensworks/LDflex-Comunica that referenced this issue May 5, 2019
@RubenVerborgh
Copy link
Member

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

After LDflex/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 Something isn't working 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
Copy link
Contributor

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

akashdeep-singh 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
Copy link
Member

RubenVerborgh 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.

@RubenVerborgh
Copy link
Member

In #30, we are unsure whether this issue was fully fixed. Might need reproducible test cases for browsers.

@michielbdejong
Copy link
Contributor

See mention there, this bug still seems to be affecting the Solid SDK?

@RubenVerborgh
Copy link
Member

Indeed; tracking this in #30.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants