{"record":{"id":"484007172179b2c0","repo":"handlebars-lang/handlebars.js","slug":"attempting-to-register-a-partial-called-name","errorCode":null,"errorMessage":"Attempting to register a partial called \"${name}\" as undefined","messagePattern":"Attempting to register a partial called \"(.+?)\" as undefined","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"lib/handlebars/base.js","lineNumber":59,"sourceCode":"    if (toString.call(name) === objectType) {\n      if (fn) {\n        throw new Exception('Arg not supported with multiple helpers');\n      }\n      extend(this.helpers, name);\n    } else {\n      this.helpers[name] = fn;\n    }\n  },\n  unregisterHelper: function (name) {\n    delete this.helpers[name];\n  },\n\n  registerPartial: function (name, partial) {\n    if (toString.call(name) === objectType) {\n      extend(this.partials, name);\n    } else {\n      if (typeof partial === 'undefined') {\n        throw new Exception(\n          `Attempting to register a partial called \"${name}\" as undefined`\n        );\n      }\n      this.partials[name] = partial;\n    }\n  },\n  unregisterPartial: function (name) {\n    delete this.partials[name];\n  },\n\n  registerDecorator: function (name, fn) {\n    if (toString.call(name) === objectType) {\n      if (fn) {\n        throw new Exception('Arg not supported with multiple decorators');\n      }\n      extend(this.decorators, name);\n    } else {\n      this.decorators[name] = fn;","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/handlebars-lang/handlebars.js/blob/13a7a679910d2adbfe7f6fad61ce8f98426b0378/lib/handlebars/base.js#L41-L77","documentation":"registerPartial throws when a partial is registered by string name but the partial value is undefined. The library refuses to create a partial whose content is undefined, since it would fail at render time.","triggerScenarios":"Handlebars.registerPartial('header', undefined) or registerPartial(name) where the value variable is undefined (e.g. a failed require/import).","commonSituations":"Dynamic partial loading where the file read or module import returned undefined; typos in variable names; bundlers tree-shaking or failing to resolve the partial module.","solutions":["Ensure the second argument is defined before registering (check the import/require result).","Use the object form registerPartial({name: content}) for bulk registration.","Guard the registration: only call registerPartial when content !== undefined."],"exampleFix":"// before\nHandlebars.registerPartial('header', require('./partials/header'));\n// after\nconst header = require('./partials/header');\nif (header !== undefined) Handlebars.registerPartial('header', header);","handlingStrategy":"validation","validationCode":"function safeRegisterPartial(hb, name, partial) {\n  if (partial === undefined) throw new Error(`Partial \"${name}\" is undefined; check import`);\n  hb.registerPartial(name, partial);\n}","typeGuard":"const isDefinedPartial = (p) => p !== undefined && (typeof p === 'string' || typeof p === 'function');","tryCatchPattern":"try { Handlebars.registerPartial(name, content); } catch (e) { console.error(`Failed to register partial ${name}:`, e.message); }","preventionTips":["Check imports/resolution of partial modules before registering.","Register partials at startup with a loader that validates content.","Prefer the object form to register many partials atomically after validating values."],"tags":["partials","undefined-value","api-misuse"],"backgroundTag":"undefined-value","analyzedSha":"13a7a679910d2adbfe7f6fad61ce8f98426b0378","analyzedAt":"2026-09-02T20:25:07.518Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}