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

showError doesn't trigger app:error (anymore?) #27152

Closed
TheDutchCoder opened this issue May 10, 2024 · 5 comments
Closed

showError doesn't trigger app:error (anymore?) #27152

TheDutchCoder opened this issue May 10, 2024 · 5 comments

Comments

@TheDutchCoder
Copy link
Contributor

Environment


  • Operating System: Linux
  • Node Version: v18.18.0
  • Nuxt Version: 3.11.2
  • CLI Version: 3.11.1
  • Nitro Version: 2.9.6
  • Package Manager: [email protected]
  • Builder: -
  • User Config: devtools
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-khtc7d?file=plugins%2Ferror-handler.js,app.vue

Describe the bug

showError is supposed to trigger the app:error hook.
However this doesn't seem to work (anymore). I'm sure it used to work in the past.
You can see the hook registering properly in the plugin, but the actual log message on error never shows up.

I also tried throwing createError, but that also yields no results.

Additional context

I noticed the docs now discourage using showError, which is new to me, but that has the same result.
image

Logs

No response

Copy link

stackblitz bot commented May 10, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@danielroe
Copy link
Member

This seems to be working for me.

CleanShot 2024-05-24 at 17 36 00@2x

You can see the implementation here, which does call the hook:

export const showError = <DataT = unknown>(
error: string | Error | (Partial<NuxtError<DataT>> & {
status?: number
statusText?: string
}),
) => {
const nuxtError = createError<DataT>(error)
try {
const nuxtApp = useNuxtApp()
const error = useError()
if (import.meta.client) {
nuxtApp.hooks.callHook('app:error', nuxtError)
}
error.value = error.value || nuxtError
} catch {
throw nuxtError
}
return nuxtError
}

Copy link
Contributor

Would you be able to provide a reproduction? 🙏

More info

Why do I need to provide a reproduction?

Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making.

What will happen?

If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritize it based on its severity and how many people we think it might affect.

If needs reproduction labeled issues don't receive any substantial activity (e.g., new comments featuring a reproduction link), we'll close them. That's not because we don't care! At any point, feel free to comment with a reproduction and we'll reopen it.

How can I create a reproduction?

We have a couple of templates for starting with a minimal reproduction:

👉 https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz
👉 https://codesandbox.io/s/github/nuxt/starter/v3-codesandbox

A public GitHub repository is also perfect. 👌

Please ensure that the reproduction is as minimal as possible. See more details in our guide.

You might also find these other articles interesting and/or helpful:

@TheDutchCoder
Copy link
Contributor Author

Oh, now it indeed started working again.

My repro 100% did not work before (and I had the same behaviour locally), so maybe this was fixed in the meantime?
Did Nitro update recently without Nuxt updating minor versions, or some other dep that might've caused this?

Anyway: this can be closed it seems!

@danielroe
Copy link
Member

Hm. I don't know what might have been causing this to fail, but it should be purely a Nuxt behaviour, and one that hasn't changed since you opened the repro...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants