{"record":{"id":"1ee6fe9cc3d68c27","repo":"handlebars-lang/handlebars.js","slug":"name-not-defined-in-obj","errorCode":null,"errorMessage":"\"${name}\" not defined in ${obj}","messagePattern":"\"(.+?)\" not defined in (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"lib/handlebars/runtime.js","lineNumber":113,"sourceCode":"          lines[i] = options.indent + lines[i];\n        }\n        result = lines.join('\\n');\n      }\n      return result;\n    } else {\n      throw new Exception(\n        'The partial ' +\n          options.name +\n          ' could not be compiled when running in runtime-only mode'\n      );\n    }\n  }\n\n  // Just add water\n  let container = {\n    strict: function (obj, name, loc) {\n      if (obj == null || !(name in Object(obj))) {\n        throw new Exception('\"' + name + '\" not defined in ' + obj, {\n          loc: loc,\n        });\n      }\n      return container.lookupProperty(obj, name);\n    },\n    strictLookup: function (depths, name, loc) {\n      const result = container.lookup(depths, name);\n      return result !== undefined\n        ? result\n        : container.strict(undefined, name, loc);\n    },\n    lookupProperty: function (parent, propertyName) {\n      if (Utils.isMap(parent)) {\n        return parent.get(propertyName);\n      }\n\n      let result = parent[propertyName];\n      if (result == null) {","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/handlebars-lang/handlebars.js/blob/13a7a679910d2adbfe7f6fad61ce8f98426b0378/lib/handlebars/runtime.js#L95-L131","documentation":"In strict mode (compile with { strict: true }), the template's strict() helper throws when a referenced identifier is null/undefined or missing on its parent object, instead of rendering empty. This surfaces missing data at render time. The loc option points at the offending template location.","triggerScenarios":"Rendering a strict-mode compiled template with data missing a referenced key, e.g. {{user.name}} where user is undefined or name is not a property of user.","commonSituations":"API responses missing fields; renamed JSON keys; tests rendering templates against fixtures that omit fields; turning strict:true on to catch typos and immediately hitting partial data.","solutions":["Provide all referenced fields in the context before rendering","Use {{#if}} or the default value syntax ({{missing}}{{else}}fallback) or compile without strict:true","Guard with lookup helpers like {{lookup obj 'name'}} or the '?:' inline-if for optional fields"],"exampleFix":"// before (throws when user.name missing)\nconst t = Handlebars.compile('{{user.name}}', { strict: true });\nt({});\n\n// after\nconst t = Handlebars.compile('{{#if user.name}}{{user.name}}{{/if}}', { strict: true });\nt({}); // renders '' instead of throwing","handlingStrategy":"try-catch","validationCode":"function hasRequiredFields(ctx, keys) {\n  return keys.every(k => k.split('.').reduce((o, p) => (o == null ? undefined : o[p]), ctx) != null);\n}\n// before render: hasRequiredFields(data, ['user.name'])","typeGuard":"function propDefined(obj, key) {\n  return obj != null && key in Object(obj);\n}","tryCatchPattern":"try {\n  return template(data);\n} catch (e) {\n  if (/\" not defined in /.test(e.message)) {\n    // log e.loc, fix data or relax strict mode\n  } else throw e;\n}","preventionTips":["Validate the data shape against the template's referenced fields before rendering","Use strict mode in tests to catch missing data early, non-strict in production if acceptable","Fixture-test every template with representative (and minimal) data","Use {{#if}}/defaults in templates for optional fields"],"tags":["handlebars","strict-mode","missing-property","template-data"],"backgroundTag":"property-not-defined-strict-mode","analyzedSha":"13a7a679910d2adbfe7f6fad61ce8f98426b0378","analyzedAt":"2026-09-02T20:25:07.518Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}