mastra-ai/mastra · error
Failure in analyze package step: ${analyzeResult.error || 'P
Error message
Failure in analyze package step: ${analyzeResult.error || 'Package analysis failed'} What it means
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.
Source
Thrown at packages/agent-builder/src/workflows/template-builder/template-builder.ts:1621
.then(cloneTemplateStep)
.map(async ({ getStepResult }) => {
const cloneResult = getStepResult(cloneTemplateStep);
// Check for failure in clone step
if (shouldAbortWorkflow(cloneResult)) {
throw new Error(`Critical failure in clone step: ${cloneResult.error}`);
}
return cloneResult;
})
.parallel([analyzePackageStep, discoverUnitsStep])
.map(async ({ getStepResult }) => {
const analyzeResult = getStepResult(analyzePackageStep);
const discoverResult = getStepResult(discoverUnitsStep);
// Check for failures in parallel steps
if (shouldAbortWorkflow(analyzeResult)) {
throw new Error(`Failure in analyze package step: ${analyzeResult.error || 'Package analysis failed'}`);
}
if (shouldAbortWorkflow(discoverResult)) {
throw new Error(`Failure in discover units step: ${discoverResult.error || 'Unit discovery failed'}`);
}
return discoverResult;
})
.then(orderUnitsStep)
.map(async ({ getStepResult, getInitData }) => {
const cloneResult = getStepResult(cloneTemplateStep);
const initData = getInitData<AgentBuilderInputSchemaType>();
return {
commitSha: cloneResult.commitSha,
slug: cloneResult.slug,
targetPath: initData.targetPath,
};
})View on GitHub (pinned to 75dd419e61)
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
Defensive patterns
Strategy: validation
Validate before calling
export function assertTemplate analyzable(dir: string) {
const pkg = JSON.parse(require('node:fs').readFileSync(`${dir}/package.json`, 'utf8'));
if (!pkg.name || !pkg.version) throw new Error('template package.json missing name/version');
}
// run against the cloned template before invoking the template-builder workflow Type guard
export function analyzeSucceeded(r: { error?: string; [k: string]: unknown }) {
return r != null && !r.error;
} Try / catch
try {
await run.start({ ... });
} catch (e) {
if (e instanceof Error && e.message.startsWith('Failure in analyze package step:')) {
const detail = e.message.split(': ').slice(1).join(': ');
if (detail !== 'Package analysis failed') console.error('Analyzer said:', detail);
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Critical failure in clone step: ${cloneResult.error}
- Failure in discover units step: ${discoverResult.error || 'U
- Failure in install step: ${installResult.error || 'Install f
- Workflow ${workflowId} not found
- Workflow ID is required
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/13e8bf075c449623.
Report an issue: GitHub.