From 59c8fb95d974db9ad75c9fe3f0b010871ad6365f Mon Sep 17 00:00:00 2001 From: ted Date: Wed, 7 Jan 2026 23:39:41 +0000 Subject: [PATCH 1/3] Log `controller not found` when controller is not found --- src/core/application.ts | 7 ++++++- src/tests/modules/core/application_tests.ts | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/core/application.ts b/src/core/application.ts index b8b92715..4d46dc1a 100644 --- a/src/core/application.ts +++ b/src/core/application.ts @@ -79,7 +79,12 @@ export class Application implements ErrorHandler { getControllerForElementAndIdentifier(element: Element, identifier: string): Controller | null { const context = this.router.getContextForElementAndIdentifier(element, identifier) - return context ? context.controller : null + if (context) { + return context.controller + } else { + this.logDebugActivity(identifier, "controller not found", { element }) + return null + } } // Error handling diff --git a/src/tests/modules/core/application_tests.ts b/src/tests/modules/core/application_tests.ts index 8cee672f..f40fd067 100644 --- a/src/tests/modules/core/application_tests.ts +++ b/src/tests/modules/core/application_tests.ts @@ -45,6 +45,23 @@ export default class ApplicationTests extends ApplicationTestCase { this.assert.ok(this.controllers[0] instanceof BController) } + "test Application#getControllerForElementAndIdentifier logs debug activity when controller not found"() { + this.application.load(this.definitions) + + const logCalls: { identifier: string; functionName: string; detail: object }[] = [] + this.application.logDebugActivity = (identifier, functionName, detail = {}) => { + logCalls.push({ identifier, functionName, detail }) + } + + const element = this.fixtureElement.querySelector("[data-controller='a']")! + const result = this.application.getControllerForElementAndIdentifier(element, "nonexistent") + + this.assert.equal(result, null) + this.assert.equal(logCalls.length, 1) + this.assert.equal(logCalls[0].identifier, "nonexistent") + this.assert.equal(logCalls[0].functionName, "controller not found") + } + get controllers() { return this.application.controllers as LogController[] } From 09c9d6d9c17524e59ae567c6f18167fda2375bfa Mon Sep 17 00:00:00 2001 From: ted Date: Thu, 8 Jan 2026 03:15:00 +0000 Subject: [PATCH 2/3] tweaking spec --- src/tests/modules/core/application_tests.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tests/modules/core/application_tests.ts b/src/tests/modules/core/application_tests.ts index f40fd067..b7a6046f 100644 --- a/src/tests/modules/core/application_tests.ts +++ b/src/tests/modules/core/application_tests.ts @@ -48,7 +48,7 @@ export default class ApplicationTests extends ApplicationTestCase { "test Application#getControllerForElementAndIdentifier logs debug activity when controller not found"() { this.application.load(this.definitions) - const logCalls: { identifier: string; functionName: string; detail: object }[] = [] + const logCalls: { identifier: string; functionName: string; detail: { element?: Element } }[] = [] this.application.logDebugActivity = (identifier, functionName, detail = {}) => { logCalls.push({ identifier, functionName, detail }) } @@ -60,6 +60,7 @@ export default class ApplicationTests extends ApplicationTestCase { this.assert.equal(logCalls.length, 1) this.assert.equal(logCalls[0].identifier, "nonexistent") this.assert.equal(logCalls[0].functionName, "controller not found") + this.assert.equal(logCalls[0].detail.element, element) } get controllers() { From b64d6254340ff430529f92c56d53d9beb53f8ec2 Mon Sep 17 00:00:00 2001 From: ted Date: Fri, 9 Jan 2026 22:57:59 +0000 Subject: [PATCH 3/3] Removing `else` and using early return for controller when there is one. --- src/core/application.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/core/application.ts b/src/core/application.ts index 4d46dc1a..5eaa9a1d 100644 --- a/src/core/application.ts +++ b/src/core/application.ts @@ -79,12 +79,10 @@ export class Application implements ErrorHandler { getControllerForElementAndIdentifier(element: Element, identifier: string): Controller | null { const context = this.router.getContextForElementAndIdentifier(element, identifier) - if (context) { - return context.controller - } else { - this.logDebugActivity(identifier, "controller not found", { element }) - return null - } + if (context) return context.controller + + this.logDebugActivity(identifier, "controller not found", { element }) + return null } // Error handling