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:
- 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}`);
}
- 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.
Summary
Scope.pushTemplateFrame()currently throws a rawTypeErrorwhen called with a template name that has no associated template context (e.g.index.hbs), becausegetTemplateContext()returnsundefinedand the subsequent destructuring fails silently into a crash.Now that
Scopeis 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:
pushTemplateFramethat checks the return value ofgetTemplateContextand throws a deliberate error, e.g.:getTemplateContextreturn a safe default context object for unknown templates instead ofundefined.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 rawTypeError.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.