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

Occurance of unhandledRejection #251

Closed
tobiasdiez opened this issue May 19, 2022 · 1 comment
Closed

Occurance of unhandledRejection #251

tobiasdiez opened this issue May 19, 2022 · 1 comment

Comments

@tobiasdiez
Copy link
Contributor

Environment

rc3

Reproduction

n/a

Describe the bug

In #212 you have asked me, when these unhandledRejection errors occur. Here are two instances:

[nitro] [dev] [unhandledRejection] Error: TypeInfo not known for "Query$2"
    at InternalDependencyContainer.construct (/workspace/JabRefOnline/node_modules/tsyringe/dist/cjs/dependency-container.js:263:23)
    at InternalDependencyContainer.resolve (/workspace/JabRefOnline/node_modules/tsyringe/dist/cjs/dependency-container.js:105:33)
    at resolvers$2 (file:///workspace/JabRefOnline/.nuxt/dev/index.mjs:596:22)
    at loadResolvers (file:///workspace/JabRefOnline/.nuxt/dev/index.mjs:971:5)
    at loadSchema (file:///workspace/JabRefOnline/.nuxt/dev/index.mjs:985:21)
    at file:///workspace/JabRefOnline/.nuxt/dev/index.mjs:1094:13

where the last line refers to https://github.com/JabRef/JabRefOnline/blob/8ebc92fc768c193ec00cdba7da8e8779b6635ac6/server/api/%5B...%5D.ts#L32

and

 ERROR  [unhandledRejection] Cannot set headers after they are sent to the client

  at new NodeError (node:internal/errors:371:5)
  at ServerResponse.setHeader (node:_http_outgoing:576:11)
  at sendError (node_modules/h3/dist/index.mjs:216:13)
  at nodeHandler (node_modules/h3/dist/index.mjs:375:15)

Additional context

No response

Logs

No response

@pi0
Copy link
Member

pi0 commented May 20, 2022

Hi @tobiasdiez, and thanks for not forgetting about that and sharing when it happens!

Well, actually the issue is in your implementation. You should never leave a promise unsupervised. In this case, you could do configureTsyringe().then(() => { ... }).catch(error => { console.error('Error while executing configureTsyringe', error) })

Unrelated: Why would you need overhead of all express and HTTP server to start an apollo server? It wouldn't even work without Node.js and I think there is a lighter version for apollo...

Regardless you can also use lazy functions to initiate server: (https://www.jsdocs.io/package/h3#defineLazyEventHandler)

export default defineLazyEventHandler(async () => {
  // Do all async stuff on first API call 
  // H3 await first on this
  await configureTsyringe() 
  const server = ...
  return defineHandler(server)
})

I'm closing issue since is not directly related to Nitro. But feel free to ping me here or in Discord if could be of any further help.

@pi0 pi0 closed this as completed May 20, 2022
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

No branches or pull requests

2 participants