{"record":{"id":"2cb81b234a545596","repo":"mastra-ai/mastra","slug":"describebadplaceholder-template-idx-rawexpr","errorCode":null,"errorMessage":"${describeBadPlaceholder(template, idx, rawExpr)} has empty or whitespace-padded contents. Use ${<scope>.<path>} with no surrounding whitespace.","messagePattern":"(.+?) has empty or whitespace-padded contents\\. Use (.+?) with no surrounding whitespace\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/workflows/mapping-template.ts","lineNumber":58,"sourceCode":"    rest: dot === -1 ? '' : rawExpr.slice(dot + 1),\n  };\n}\n\n/**\n * Validates a `{ template }` source's syntax at workflow-definition time.\n * Throws if any placeholder is empty, whitespace-padded, references an unknown\n * namespace, or is a malformed `stepResults.<stepId>` / `stepResults.<stepId>.<path>` shape.\n *\n * Run-time concerns (does the step actually exist, does the path resolve, is\n * the value a primitive) stay in {@link resolveTemplate}.\n */\nexport function validateTemplate(template: string): void {\n  let idx = 0;\n  for (const match of template.matchAll(TEMPLATE_PLACEHOLDER)) {\n    idx++;\n    const rawExpr = match[1] ?? '';\n    if (rawExpr.length === 0 || rawExpr !== rawExpr.trim()) {\n      throw new Error(\n        `${describeBadPlaceholder(template, idx, rawExpr)} has empty or whitespace-padded contents. ` +\n          `Use \\${<scope>.<path>} with no surrounding whitespace.`,\n      );\n    }\n    const { scope, rest } = parseTemplatePlaceholder(rawExpr);\n    if (scope === 'stepResults') {\n      const innerDot = rest.indexOf('.');\n      const stepId = innerDot === -1 ? rest : rest.slice(0, innerDot);\n      if (!stepId) {\n        throw new Error(\n          `${describeBadPlaceholder(template, idx, rawExpr)} must be of the form \\${stepResults.<stepId>} or \\${stepResults.<stepId>.<path>}.`,\n        );\n      }\n      continue;\n    }\n    if (scope === 'requestContext') {\n      if (!rest) {\n        throw new Error(","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/workflows/mapping-template.ts#L40-L76","documentation":"validateTemplate parses every ${...} placeholder in a mapping template. An empty expression (\"${}\") or one with surrounding whitespace (\"${ foo }\") is rejected because placeholder contents must be exactly <scope>.<path> with no padding. describeBadPlaceholder prefixes the message with the template and placeholder position.","triggerScenarios":"Writing \"${}\" or \"${ stepResults.myStep }\" (spaces inside braces) in a template passed to mapVariable/map/analyzeMapConfig.","commonSituations":"Copy-pasting templates from docs with formatting; IDEs/formatters inserting spaces; leaving an empty placeholder after deleting a variable name.","solutions":["Remove surrounding whitespace inside the braces: \"${stepResults.myStep}\".","Replace empty \"${}\" with a concrete scope.path reference or remove the placeholder.","Validate templates at build time by calling validateTemplate() in a unit test for each mapping."],"exampleFix":"// before\nmapVariable({ value: '${ stepResults.fetchUser }' });\n// after\nmapVariable({ value: '${stepResults.fetchUser}' });","handlingStrategy":"validation","validationCode":"import { validateTemplate } from './mapping-template';\n['${stepResults.fetchUser.name}'].forEach(t => validateTemplate(t)); // throws on '${ stepResults.x }' or '${}'","typeGuard":"function isCleanPlaceholder(expr: string): boolean {\n  return expr.length > 0 && expr === expr.trim();\n}","tryCatchPattern":"try {\n  validateTemplate(tpl);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('whitespace-padded')) {\n    tpl = tpl.replace(/\\$\\{\\s*([^}]*?)\\s*\\}/g, '${$1}');\n  } else throw err;\n}","preventionTips":["Never type spaces inside ${...}; write ${scope.path} exactly.","Run validateTemplate() in unit tests for every mapping template constant.","Watch for editor auto-formatting inserting spaces inside braces."],"tags":["workflow","template","mapping","syntax"],"backgroundTag":"template-syntax-error","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}