{"record":{"id":"b11d1e1e0ab2f1df","repo":"mastra-ai/mastra","slug":"no-template-selected","errorCode":null,"errorMessage":"No template selected","messagePattern":"No template selected","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/create/create.ts","lineNumber":732,"sourceCode":"    mcp: [],\n    tools: [],\n    networks: [],\n    workflows: [],\n  };\n}\n\nasync function resolveTemplate(mode: Exclude<CreateMode, 'empty'>, template?: string | boolean): Promise<Template> {\n  if (mode === 'managed') return DEFAULT_TEMPLATE;\n\n  if (template === true) {\n    const templates = await loadTemplates();\n    const selected = await runCreatePrompt(signal => selectTemplate(templates, { signal }));\n    if (!selected) cancelCreate();\n    return selected;\n  }\n\n  if (typeof template !== 'string') {\n    throw new Error('No template selected');\n  }\n\n  const githubUrl = parseGitHubRepositoryUrl(template);\n  if (githubUrl) {\n    const spinner = p.spinner();\n    spinner.start('Validating GitHub repository...');\n    const validation = await validateGitHubProject(githubUrl);\n    if (!validation.isValid) {\n      spinner.stop('Validation failed');\n      p.log.error('This does not appear to be a valid Mastra project:');\n      validation.errors.forEach(error => p.log.error(`  - ${error}`));\n      throw new Error('Invalid Mastra project');\n    }\n    spinner.stop('Valid Mastra project ✓');\n    return createFromGitHubUrl(githubUrl);\n  }\n  if (looksLikeGitHubUrl(template)) {\n    throw new Error('Invalid GitHub repository URL. Use https://github.com/<owner>/<repository>.');","sourceCodeStart":714,"sourceCodeEnd":750,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/create/create.ts#L714-L750","documentation":"`resolveTemplate` in packages/cli/src/commands/create/create.ts:731 throws 'No template selected' when the `template` argument is neither `true` (interactive selection) nor a usable string. This is a defensive guard for the impossible-in-CLI case where template mode was requested but the value resolved to a non-string, non-boolean (e.g. undefined via the programmatic API while mode was computed as 'template').","triggerScenarios":"Calling `create()` programmatically with `{ template: <slug from a variable> }` where the variable is undefined/null at runtime, while options.empty is false so the mode resolves to 'template' (e.g. `template: process.env.TEMPLATE` with the env var unset).","commonSituations":"Scripting the create API with config-driven template slugs that are missing/empty; TS types bypassed via JSON.parse of CLI input; refactors leaving template undefined while still forcing template mode.","solutions":["Ensure a template slug/URL string is actually passed: `--template template-agent-harness`","When scripting the API, validate the template value is a non-empty string before calling create()","Use `--template` with no value to get interactive selection instead of an undefined value","Check the env/config source feeding the template argument for typos or unset values"],"exampleFix":"// before\nawait create({ template: process.env.TEMPLATE }); // undefined -> throws\n// after\nconst template = process.env.TEMPLATE;\nif (typeof template !== 'string' || template.length === 0) {\n  throw new Error('TEMPLATE env var must be set to a template slug or GitHub URL');\n}\nawait create({ template });","handlingStrategy":"validation","validationCode":"function assertTemplateProvided(template: string | boolean | undefined): asserts template is string | boolean {\n  if (template === undefined || template === null || template === '') {\n    throw new Error('template must be true (interactive) or a non-empty slug/GitHub URL');\n  }\n}","typeGuard":"function hasTemplate(t: unknown): t is string | boolean {\n  return typeof t === 'string' ? t.length > 0 : typeof t === 'boolean';\n}","tryCatchPattern":"try {\n  await create({ template });\n} catch (error) {\n  if (error instanceof Error && error.message === 'No template selected') {\n    console.error('Template mode was requested but no template value was provided');\n  } else throw error;\n}","preventionTips":["Coalesce env/config template values before calling create: template ?? 'template-agent-harness'","Enable TS strictness so undefined can't silently reach the template option","When driving from env vars, fail early if the variable is unset","Use --template with no value to enter interactive selection instead of an undefined value"],"tags":["cli","template","input-validation","programmatic-api"],"backgroundTag":"missing-required-option","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}