hotwired / stimulus

A modest JavaScript framework for the HTML you already have

Home Page:https://stimulus.hotwired.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handle error when controller not found

tmaier opened this issue · comments

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.

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