Errors in user custom functions in apollo object makes Nuxt crash

bviala
0
bviala
commented 6 months ago

Version

v4.0.0-rc.2

Reproduction link

https://github.com/bviala/nuxt-apollo-crash

Steps to reproduce

clone the repo
npm run dev (or build / start)
access localhost:3000
check your terminal to see that the server crashed

Check pages/index.vue to see the code causing the issue.
It looks like any error happening in custom code passed to the apollo object will make the server crash.

What is expected ?

Server not crashing ๐Ÿ˜ฌ

What is actually happening?

Server crashing ๐Ÿ˜ญ

Additional comments?

I'm not sure if this is a nuxt/apollo or a nuxt issue ๐Ÿค”

bug
0
dohomi
1.4k
dohomi
commented 3 months ago

Please update to rc-4 - this should work if not reopen again

0
bviala
0
bviala
commented 3 months ago

rc4 didn't correct this issue. I updated reproduction repo

0
dohomi
1.4k
dohomi
commented 3 months ago

@bviala you must raise the dependency of Nuxt and you have to make sure that Vue is in version 2.6+ as well as the vue-server-renderer. I can see in your package-lock that it still runs in version 2.5.x which will break your built: https://github.com/nuxt-community/apollo-module#warning

0
bviala
0
bviala
commented 3 months ago

Hmm I'm confused, what is wrong with the package lock ?
I checked it and vue, vue-server-renderer and vue-template-compiler are in version 2.6.6.
I tried to install them as direct dependency as advised in your link and it didn't change the package-lock, and it still crashes.
Can you confirm that you can't reproduce ?

0
dohomi
1.4k
dohomi
commented 3 months ago

@bviala my bad sorry I overlooked it. But I also don't have an idea whats going wrong in your case, sorry..

0
dohomi
1.4k
dohomi
commented 3 months ago

@bviala what are you doing here: https://github.com/bviala/nuxt-apollo-crash/blob/master/pages/index.vue#L32
If you throw an error in update hook of apollo it will always be an error

0
bviala
0
bviala
commented 3 months ago

The throw is to demonstrate that any error in the custom functions passed to apollo will make Nuxt to crash.
The issue is not a particular error, the issue is that Nuxt crashes if an error happens there.
Like the whole server crashes. The process ends with exit code 1.
I don't know enough to tell if it's a apollo module issue or a nuxt issue, or even a vue-apollo issue, but it seems quite a serious problem to me.

0
dohomi
1.4k
dohomi
commented 3 months ago

@bviala if you run server side code (as you are using mode:universal) then for sure your app is not proceeding. This is how vue-apollo works as its prefetching the code on server side. You can add some error handling but you need to refer to the vue-apollo docs how to handle it. For me your example does not make any sense to be honest: you are in charge of the code, so why should an error happens in your update hook? If you write NodeJS code failures and you don't catch them your NodeJS server crashes as well.

0
bviala
0
bviala
commented 3 months ago

I don't understand your reasoning at all.
Node is just a runtime. Nuxt is a web server framework. In this context, crashing if any error occurs during a request is definitely not ok.
Server side errors happen all the time in Vue code without Nuxt crashing, and it's the same with every web server framework. An error in an Express middleware doesn't make the server crash.

No developer is perfect, and errors do happens. A Nuxt project shouldn't crash just because the developer never figured that he should wrap his apollo update hooks in try catch blocks.
I'm lucky I found out this in development stage, but it could as well have been on a large critical website in production.

Maybe it is the throws that confuses you ? I can develop a real world case if it helps.

0
dohomi
1.4k
dohomi
commented 3 months ago

@bviala address your issue on vue-apollo directly. This package is just a convenient wrapper for the functionality of vue-apollo in use with NuxtJS. There won't be any fix possible, at least I would know of. If you have any improvement how to fix your issue I am happy to receive any PR.

0
Informations
Bug Report โ€ข Open
#c162 - Created 6 months ago