{"record":{"id":"d0501fc58059f3c4","repo":"mastra-ai/mastra","slug":"invalid-path-path-in-errorlabel","errorCode":null,"errorMessage":"Invalid path ${path} in ${errorLabel}","messagePattern":"Invalid path (.+?) in (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/workflows/mapping-template.ts","lineNumber":19,"sourceCode":"/**\n * The `${scope.path}` mapping-template DSL used by `.map()` template sources.\n *\n * Definition-time syntax checks live in {@link validateTemplate}; run-time\n * resolution (path lookup + value coercion) lives in {@link resolveTemplate}.\n * This module has no knowledge of the step-entry union — it is a pure\n * string-DSL interpreter over a step's execute context.\n */\n\n/** Walks a dotted path on an object. `''` or `'.'` returns the root unchanged. */\nexport function traverseMappingPath(root: unknown, path: string, errorLabel: string): unknown {\n  if (path === '' || path === '.') return root;\n  const parts = path.split('.');\n  let value: any = root;\n  for (const part of parts) {\n    if (typeof value === 'object' && value !== null) {\n      value = value[part];\n    } else {\n      throw new Error(`Invalid path ${path} in ${errorLabel}`);\n    }\n  }\n  return value;\n}\n\nconst TEMPLATE_PLACEHOLDER = /\\$\\{([^}]*)\\}/g;\n\nconst TEMPLATE_NAMESPACES = ['inputData', 'initData', 'state', 'requestContext', 'stepResults'] as const;\ntype TemplateScope = (typeof TEMPLATE_NAMESPACES)[number];\n\n/** Common error-message prefix so every template diagnostic points at the exact placeholder. */\nfunction describeBadPlaceholder(template: string, idx: number, rawExpr: string): string {\n  return `Template placeholder #${idx} (\\${${rawExpr}}) in '${template}'`;\n}\n\n/** Split a placeholder body `scope.path.with.dots` into its leading scope and the dotted remainder. */\nfunction parseTemplatePlaceholder(rawExpr: string): { scope: string; rest: string } {\n  const dot = rawExpr.indexOf('.');","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/workflows/mapping-template.ts#L1-L37","documentation":"traverseMappingPath walks a dot-separated path (e.g. \"user.address.city\") through an object. If any intermediate value along the path is not a non-null object (undefined, null, or a primitive), the path cannot be traversed and it throws identifying the path and the mapping/template label it occurred in.","triggerScenarios":"A mapping entry or ${...} template placeholder references e.g. stepResults.myStep.result.detail while stepResults.myStep.result is undefined or a scalar (step output shaped differently than expected).","commonSituations":"Renaming fields in a step's output without updating downstream mapVariable/toRoute mappings; a step returning a string/number where an object was assumed; optional output fields absent at runtime.","solutions":["Align the path with the actual step output shape (log the step result to inspect it).","Shorten the path to the last existing object level, or restructure the producing step to emit the nested object.","Use optional/default handling upstream (e.g. normalize the output in the producing step) before mapping."],"exampleFix":"// before\nmapVariable({ value: '${stepResults.fetchUser.data.profile.email}' }) // data is a string\n// after\nmapVariable({ value: '${stepResults.fetchUser.email}' })","handlingStrategy":"validation","validationCode":"function assertPath(obj: unknown, path: string): void {\n  let cur: any = obj;\n  for (const part of path.split('.')) {\n    if (typeof cur !== 'object' || cur === null) throw new Error(`Path '${path}' invalid at '${part}'`);\n    cur = cur[part];\n  }\n}","typeGuard":"function isNonPlainValue(v: unknown): v is Record<string, unknown> {\n  return typeof v === 'object' && v !== null;\n}","tryCatchPattern":"try {\n  run.workflow.mapVariable({ value: '${stepResults.myStep.detail.x}' });\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Invalid path')) {\n    console.error('Mapping path mismatch with step output shape:', err.message);\n  } else throw err;\n}","preventionTips":["Keep step output shapes in typed constants shared between producing and consuming steps.","Log or unit-test step outputs after shape changes; update all mapping paths.","Prefer shorter paths into the shallowest stable object level."],"tags":["workflow","mapping","path-traversal","configuration"],"backgroundTag":"invalid-mapping-path","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}