Skip to content

Fix pushTemplateFrame to throw deliberate domain error for unsupported templates (e.g. index.hbs) #727

@coderabbitai

Description

@coderabbitai

Summary

Scope.pushTemplateFrame() currently throws a raw TypeError when called with a template name that has no associated template context (e.g. index.hbs), because getTemplateContext() returns undefined and the subsequent destructuring fails silently into a crash.

Now that Scope is a public API (as of #721), this implicit crash should be replaced with an explicit, descriptive domain error so callers can reason about unsupported template names.

Proposed Fix

Either:

  1. Add a guard in pushTemplateFrame that checks the return value of getTemplateContext and throws a deliberate error, e.g.:
    const context = getTemplateContext(templateFileName);
    if (!context) {
        throw new Error(`No template context found for template: ${templateFileName}`);
    }
  2. Or have getTemplateContext return a safe default context object for unknown templates instead of undefined.

Once the implementation is updated, the test in test/scope.test.js (around lines 42–47) should be updated to assert the explicit error message/type rather than a raw TypeError.

Context

Flagged in #721 (comment: #721 (comment)) during the Mocha → Vitest migration, where the test was updated to assert .should.throw(TypeError) — locking in the crash as the public contract rather than treating it as a bug.

Requested by @troyciesco.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions