{"record":{"id":"373a4cab437b3258","repo":"mastra-ai/mastra","slug":"failed-to-load-templates-please-check-your-intern","errorCode":null,"errorMessage":"Failed to load templates. Please check your internet connection and try again.","messagePattern":"Failed to load templates\\. Please check your internet connection and try again\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/utils/template-utils.ts","lineNumber":26,"sourceCode":"  mcp: string[];\n  tools: string[];\n  networks: string[];\n  workflows: string[];\n}\n\nconst TEMPLATES_API_URL = process.env.MASTRA_TEMPLATES_API_URL || 'https://mastra.ai/api/templates.json';\n\nexport async function loadTemplates(): Promise<Template[]> {\n  try {\n    const response = await fetch(TEMPLATES_API_URL);\n    if (!response.ok) {\n      throw new Error(`Failed to fetch templates: ${response.statusText}`);\n    }\n    const templates = (await response.json()) as Template[];\n    return templates;\n  } catch (error) {\n    console.error('Error loading templates:', error);\n    throw new Error('Failed to load templates. Please check your internet connection and try again.');\n  }\n}\n\nfunction pluralize(count: number, singular: string, plural?: string): string {\n  return count === 1 ? singular : plural || `${singular}s`;\n}\n\nexport async function selectTemplate(\n  templates: Template[],\n  options: { signal?: AbortSignal } = {},\n): Promise<Template | null> {\n  const choices = templates.map(template => {\n    const parts = [];\n    if (template.agents?.length) {\n      parts.push(`${template.agents.length} ${pluralize(template.agents.length, 'agent')}`);\n    }\n    if (template.tools?.length) {\n      parts.push(`${template.tools.length} ${pluralize(template.tools.length, 'tool')}`);","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/utils/template-utils.ts#L8-L44","documentation":"The catch-all wrapper error from loadTemplates: any failure in fetching or parsing the templates JSON (including error 1008) is logged to console.error and rethrown as this user-facing message. It means the templates list could not be retrieved — usually a connectivity problem, but also any non-OK HTTP response or invalid JSON.","triggerScenarios":"Any loadTemplates call (via the templates CLI command) where fetch throws (DNS failure, offline, connection refused), the response is !ok (1008), or response.json() fails to parse.","commonSituations":"Working offline or on a flaky network; DNS/proxy/firewall blocking mastra.ai; mastra.ai outage; a custom MASTRA_TEMPLATES_API_URL serving HTML or invalid JSON instead of a Template[] JSON body.","solutions":["Verify internet connectivity and that https://mastra.ai/api/templates.json is reachable, then retry.","Check console output for the logged underlying error (the original error is printed via console.error before this throw) to see the true cause.","If MASTRA_TEMPLATES_API_URL is set, confirm it returns valid JSON and unset it to test the default endpoint.","Bypass the templates listing and scaffold manually (e.g. npx create-mastra with a known template) if the API is down."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"try {\n  const res = await fetch(process.env.MASTRA_TEMPLATES_API_URL || 'https://mastra.ai/api/templates.json');\n  await res.json(); // throws here if response is not valid JSON\n} catch { console.warn('Templates API unreachable; proceeding without it'); }","typeGuard":null,"tryCatchPattern":"try {\n  const templates = await loadTemplates();\n} catch (err) {\n  // Underlying cause was already logged via console.error by loadTemplates\n  console.error('Templates unavailable, check connectivity or MASTRA_TEMPLATES_API_URL');\n  const templates: Template[] = []; // fallback to empty list / offline path\n}","preventionTips":["Check network connectivity/DNS/proxy before running template commands.","Read the console.error output, which contains the real underlying error.","Validate any custom MASTRA_TEMPLATES_API_URL returns valid JSON arrays.","Provide an offline fallback path when the templates API is optional to your flow."],"tags":["network","http","cli","offline"],"backgroundTag":"network-request-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}