Skip to content

[BUG] :getTemplate() throws TypeError for unknown template instead of returning undefined as documented #1988

@SHUBHANSHU602

Description

@SHUBHANSHU602

Describe the bug.

The getTemplate function in apps/generator/lib/templates/bakedInTemplates.js does not handle the case where a template name does not exist in the baked-in templates list.

According to the JSDoc:

Image

The function should return undefined when the template is not found.

However, when a non-existing template name is passed, the function throws a TypeError due to attempting to access .name on undefined.

Expected behavior

When a template is not found, the function should:

Either return undefined (as documented),
Or throw a meaningful, explicit error such as:

throw new Error(Core template "${templateName}" not found.);

It should not throw an unintended TypeError.

Screenshots

Image

How to Reproduce

Navigate to:
generator/apps/generator/lib/templates

Start Node REPL:
node

Run:
const baked = require('./bakedInTemplates');
baked.getTemplate('this-template-does-not-exist');

Observe the crash:
TypeError: Cannot read properties of undefined (reading 'name')

🖥️ Device Information [optional]

  • Operating System (OS):Windows11
  • Browser:Brave
  • Browser Version:

👀 Have you checked for similar open issues?

  • 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions