generator icon indicating copy to clipboard operation
generator copied to clipboard

[BUG] :Silent failure when loading local hooks: errors are swallowed, making broken templates hard to debug

Open SHUBHANSHU602 opened this issue 10 months ago • 7 comments

Describe the bug.

While reviewing the hook registration logic and related tests, I noticed that errors occurring during local hook loading are silently ignored. If a hook file throws during import, the generator proceeds without any warning, error, or debug output.

This behavior is explicitly asserted in tests and can lead to invisible failures in templates, especially for template authors who rely on hooks for core logic.

Expected behavior

At minimum, hook load failures should be visible.

Non-breaking options that would significantly improve DX: Log a warning when a hook fails to load Include hook load errors when debug: true Expose which hooks were skipped due to errors Provide structured feedback (without throwing) The generator does not need to fail, but it should not fail silently.

Screenshots

Image Image

How to Reproduce

Clone the repo open the test/hookregister.test.js file Analyze this line

Image

🖥️ Device Information [optional]

  • Operating System (OS): WINDOWS 11
  • Browser: BRAVE
  • Browser Version:

👀 Have you checked for similar open issues?

  • [x] I checked and didn't find similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

Yes I am willing to submit a PR!

SHUBHANSHU602 avatar Jan 28 '26 08:01 SHUBHANSHU602

You're right—errors during local hook loading are currently swallowed without any warning, logging, or debug output. The implementation in hooksRegistry.js simply rejects the promise if a hook import fails, but unless the caller handles this, nothing is surfaced to the user. The tests in hooksRegistry.test.js explicitly assert this silent failure behavior, confirming what you observed: broken hooks are hard to debug because failures are invisible and the generator just proceeds as if nothing happened (source).

To improve this, you could add warning logs when a hook fails to load, optionally include error details when debug mode is enabled, and collect info on which hooks were skipped due to errors. This could be done in registerLocalHooks by catching errors, logging them (using the generator's logger or console.warn), and optionally pushing structured error info to a collection for later reporting. This way, the generator doesn't fail, but failures are no longer silent.

The relevant code to update is in apps/generator/lib/hooksRegistry.js (registerLocalHooks and registerHooks), and the tests are in apps/generator/test/hooksRegistry.test.js (source). When you make these changes, consider adding tests that assert warnings are logged and errors are reported when hooks fail to load.

Your plan to submit a PR for this is spot on and will definitely improve the developer experience!

To reply, just mention @dosu.


Docs are dead. Just use Dosu.

Leave Feedback Ask Dosu about generator Share Dosu with your team

dosubot[bot] avatar Jan 28 '26 08:01 dosubot[bot]

hey , @Adi-204 please have a look at this . Happy to raise PR if you agree with this.

SHUBHANSHU602 avatar Jan 28 '26 09:01 SHUBHANSHU602

Hey @SHUBHANSHU602, thanks for looking into this, but I don't think this is a valid bug. The production code does propagate hook errors when require(filePath) throws inside registerLocalHooks, the catch block calls reject(e), which bubbles up through registerHooks() → configureTemplateWorkflow() → generate(). The generator does not continue silently; it fails with the error. The confusion comes from the test. It has jest.mock('fs') at the top, which means xfs.walk() never emits any file events against the mocked filesystem. The broken hook require() is never actually called the promise just resolves via the end event with empty hooks. But maybe worth changing that test case.

Adi-204 avatar May 28 '26 17:05 Adi-204

So should I look into test cases @Adi-204 ?

SHUBHANSHU602 avatar May 28 '26 17:05 SHUBHANSHU602

well I don't know did you first understand what I'm trying to say?

The problem is that registerLocalHooks uses xfs.walk() (from the fs.extra package), and fs.extra internally depends on fs. With fs mocked out, the walker had no real filesystem to walk it would start up, find nothing, and immediately fire its end event. The file event handler (where require(hookFile) lives) never ran.

So you can mocked utils and fs.extra explicitly instead of relying on the side effects of a mocked fs trickling down into xfs.walk. But mocking xfs.walk won't be super easy you will have to research and look into it.

Adi-204 avatar May 28 '26 17:05 Adi-204

Ohk

SHUBHANSHU602 avatar May 28 '26 17:05 SHUBHANSHU602

No more valid issue.

SHUBHANSHU602 avatar Aug 18 '26 15:08 SHUBHANSHU602