{"record":{"id":"13e8bf075c449623","repo":"mastra-ai/mastra","slug":"failure-in-analyze-package-step-analyzeresult-e","errorCode":null,"errorMessage":"Failure in analyze package step: ${analyzeResult.error || 'Package analysis failed'}","messagePattern":"Failure in analyze package step: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent-builder/src/workflows/template-builder/template-builder.ts","lineNumber":1621,"sourceCode":"  .then(cloneTemplateStep)\n  .map(async ({ getStepResult }) => {\n    const cloneResult = getStepResult(cloneTemplateStep);\n\n    // Check for failure in clone step\n    if (shouldAbortWorkflow(cloneResult)) {\n      throw new Error(`Critical failure in clone step: ${cloneResult.error}`);\n    }\n\n    return cloneResult;\n  })\n  .parallel([analyzePackageStep, discoverUnitsStep])\n  .map(async ({ getStepResult }) => {\n    const analyzeResult = getStepResult(analyzePackageStep);\n    const discoverResult = getStepResult(discoverUnitsStep);\n\n    // Check for failures in parallel steps\n    if (shouldAbortWorkflow(analyzeResult)) {\n      throw new Error(`Failure in analyze package step: ${analyzeResult.error || 'Package analysis failed'}`);\n    }\n\n    if (shouldAbortWorkflow(discoverResult)) {\n      throw new Error(`Failure in discover units step: ${discoverResult.error || 'Unit discovery failed'}`);\n    }\n\n    return discoverResult;\n  })\n  .then(orderUnitsStep)\n  .map(async ({ getStepResult, getInitData }) => {\n    const cloneResult = getStepResult(cloneTemplateStep);\n    const initData = getInitData<AgentBuilderInputSchemaType>();\n    return {\n      commitSha: cloneResult.commitSha,\n      slug: cloneResult.slug,\n      targetPath: initData.targetPath,\n    };\n  })","sourceCodeStart":1603,"sourceCodeEnd":1639,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/agent-builder/src/workflows/template-builder/template-builder.ts#L1603-L1639","documentation":"After cloneTemplateStep, analyzePackageStep and discoverUnitsStep run in parallel; this map step inspects analyzePackageStep and, if shouldAbortWorkflow(analyzeResult) is true, throws 'Failure in analyze package step' with the step's error (or a generic fallback message). It marks package analysis as fatal for the template build.","triggerScenarios":"analyzePackageStep aborted while inspecting the cloned template's package.json/structure: unreadable or missing package.json in the clone, malformed fields it depends on, or filesystem errors accessing the cloned templateDir (e.g. clone produced an empty dir).","commonSituations":"Templates whose package.json lacks required fields the analyzer expects, clone succeeded but checkout is empty (wrong ref), or the analyze step's own parser hit unexpected content and returned an error result instead of throwing.","solutions":["Inspect analyzeResult.error in the message for the analyzer's specific complaint and fix the template's package.json/structure accordingly","Verify the cloned directory actually contains the expected files (correct branch/commit was cloned)","Run the analyzer's logic locally against the template copy to reproduce the failure","If the fallback text 'Package analysis failed' appears, add/inspect step logging to surface the real cause"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"export function assertTemplate analyzable(dir: string) {\n  const pkg = JSON.parse(require('node:fs').readFileSync(`${dir}/package.json`, 'utf8'));\n  if (!pkg.name || !pkg.version) throw new Error('template package.json missing name/version');\n}\n// run against the cloned template before invoking the template-builder workflow","typeGuard":"export function analyzeSucceeded(r: { error?: string; [k: string]: unknown }) {\n  return r != null && !r.error;\n}","tryCatchPattern":"try {\n  await run.start({ ... });\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Failure in analyze package step:')) {\n    const detail = e.message.split(': ').slice(1).join(': ');\n    if (detail !== 'Package analysis failed') console.error('Analyzer said:', detail);\n  }\n  throw e;\n}","preventionTips":["Ensure templates always contain a complete, valid package.json at their root","Verify the requested ref actually contains the expected files (avoid empty checkouts)","Lint template structure (required fields/dirs) in template CI","Surface analyzeResult.error in logs instead of relying on the generic fallback message"],"tags":["workflow","template-builder","analysis"],"backgroundTag":"workflow-step-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}