{"record":{"id":"d36197eb5618ec46","repo":"plotly/plotly.js","slug":"variable-key-in-name-could-not-be-found-p","errorCode":null,"errorMessage":"Variable '${key}' in ${name} could not be found! Please verify that the template is correct. Using value: '${fallbackValue}'.","messagePattern":"Variable '(.+?)' in (.+?) could not be found! Please verify that the template is correct\\. Using value: '(.+?)'\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/lib/index.js","lineNumber":1143,"sourceCode":"                if (!obj) continue;\n                if (obj.hasOwnProperty(key)) {\n                    value = obj[key];\n                    break;\n                }\n\n                if (!SIMPLE_PROPERTY_REGEX.test(key)) {\n                    // true here means don't convert null to undefined\n                    value = lib.nestedProperty(obj, key).get(true);\n                }\n                if (value !== undefined) break;\n            }\n        }\n\n        if (value === undefined) {\n            const { count, max, name } = opts;\n            const fallbackValue = fallback === false ? match : fallback;\n            if (count < max) {\n                lib.warn(\n                    [\n                        `Variable '${key}' in ${name} could not be found!`,\n                        'Please verify that the template is correct.',\n                        `Using value: '${fallbackValue}'.`\n                    ].join(' ')\n                );\n            }\n            if (count === max) lib.warn(`Too many '${name}' warnings - additional warnings will be suppressed.`);\n            opts.count++;\n\n            return fallbackValue;\n        }\n\n        if (parsedOp === '*') value *= parsedNumber;\n        if (parsedOp === '/') value /= parsedNumber;\n\n        if (format) {\n            var fmt;","sourceCodeStart":1125,"sourceCodeEnd":1161,"githubUrl":"https://github.com/plotly/plotly.js/blob/1d090e0b5ffb8d0fdf6e0e4ff51d3f3cf67f1314/src/lib/index.js#L1125-L1161","documentation":"plotly.js's internal template-string helper substitutes placeholders like %{x} or ${key} in attribute strings. When a referenced variable is undefined, it warns that the variable could not be found and falls back to a fallback value (either the raw match or a caller-supplied fallback). This indicates a malformed or over-generic template rather than a fatal error.","triggerScenarios":"Calling the templating helper (src/lib/index.js templater) with a string containing a placeholder key that is absent from the provided data object, e.g. templater('Value: ${foo}', {bar: 1}).","commonSituations":"Typos in template keys, data objects with optional fields left undefined, renaming an object property without updating the template, or localized/custom attribute strings referencing removed variables.","solutions":["Verify the template key spelling matches a property present in the supplied object.","Provide the missing variable in the data object passed to the templater.","Pass a sensible `fallback` option so the substitution uses a known value instead of the raw placeholder.","If this comes from plotly internals (attribute text interpolation), check that the trace/layout attribute value you set matches the expected format."],"exampleFix":"// before\ntemplater('Hello ${name}!', {nmae: 'Ada'});\n// after\ntemplater('Hello ${name}!', {name: 'Ada'});","handlingStrategy":"validation","validationCode":"function validateTemplateVars(template, data) {\n  const missing = [...template.matchAll(/\\$\\{(\\w+)\\}/g)]\n    .map(m => m[1])\n    .filter(k => data[k] === undefined);\n  if (missing.length) throw new Error(`Missing template vars: ${missing}`);\n}","typeGuard":"function hasVar(data, key) { return typeof data === 'object' && data !== null && data[key] !== undefined; }","tryCatchPattern":null,"preventionTips":["Centralize template strings and unit-test them against their expected data shapes.","Provide defaults for optional fields before templating (value ?? fallback).","Pass a fallback option to the templater for optional variables."],"tags":["templating","undefined-variable","string-interpolation"],"backgroundTag":"template-variable-not-found","analyzedSha":"1d090e0b5ffb8d0fdf6e0e4ff51d3f3cf67f1314","analyzedAt":"2026-09-02T22:03:39.906Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}