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

Handle error when controller not found #712

Open
tmaier opened this issue Aug 3, 2023 · 3 comments
Open

Handle error when controller not found #712

tmaier opened this issue Aug 3, 2023 · 3 comments

Comments

@tmaier
Copy link

tmaier commented Aug 3, 2023

Lets assume I am referencing a controller at data-controller="does-not-exist", which does not exist.
This can happen due to a typo - or because the controller has not been loaded for some reason (e.g. not in the load path, caching issue etc.)

When I see it correctly, this would never get raised. Not as an exception. Not even when the debug mode is enabled.

What is the rigtht approach to get this noticable? I would prefer if I can see it in my console when debug mode is enabled and when this will be handled by Application#handleError.

@tmaier
Copy link
Author

tmaier commented Aug 3, 2023

I believe this is the culprit:

getControllerForElementAndIdentifier(element: Element, identifier: string): Controller | null {
const context = this.router.getContextForElementAndIdentifier(element, identifier)
return context ? context.controller : null
}

It just swallows (returns null), if no controller has been found

@Ted-Tash
Copy link

@tmaier

Hello, if it is OK with you, I would love to work on this. My coworkers and I were speaking of this exact issue, and I thought it would be a fun way to contribute. I was excited to see someone had already opened an issue to track it.

@tmaier
Copy link
Author

tmaier commented May 10, 2024

Hi @Ted-Tash, this would be great!

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

No branches or pull requests

2 participants