{"record":{"id":"618c763b5a822f9e","repo":"mastra-ai/mastra","slug":"failed-to-fetch-logs-error-detail","errorCode":null,"errorMessage":"Failed to fetch logs: ${error.detail}","messagePattern":"Failed to fetch logs: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/studio/deploy-logs.ts","lineNumber":15,"sourceCode":"import { writeBarLine } from '../../utils/clack-bar.js';\nimport { authHeaders, createApiClient, MASTRA_PLATFORM_API_URL, platformFetch } from '../auth/client.js';\nimport { getToken, getCurrentOrgId, validateOrgAccess } from '../auth/credentials.js';\n\nasync function getLogs(deployId: string, tail: string | undefined, token: string, orgId: string) {\n  const client = createApiClient(token, orgId);\n  const { data, error } = await client.GET('/v1/studio/deploys/{id}/logs', {\n    params: {\n      path: { id: deployId },\n      query: tail ? { tail } : undefined,\n    },\n  });\n\n  if (error) {\n    throw new Error(`Failed to fetch logs: ${error.detail}`);\n  }\n\n  if (data.logs) {\n    for (const line of data.logs.split('\\n')) {\n      if (line) await writeBarLine(line);\n    }\n  } else {\n    console.info('(no logs available)');\n  }\n}\n\nasync function streamLogs(deployId: string, token: string, orgId: string) {\n  const url = `${MASTRA_PLATFORM_API_URL}/v1/studio/deploys/${deployId}/logs/stream`;\n\n  const resp = await platformFetch(url, {\n    headers: {\n      ...authHeaders(token, orgId),\n      Accept: 'text/event-stream',","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/studio/deploy-logs.ts#L1-L33","documentation":"Thrown by getLogs in the CLI's studio deploy-logs command when the platform API returns an error response for the deploy logs fetch. The error carries the API-provided `detail` field, so the message reflects the server's reason (auth failure, unknown deploy ID, permissions, etc.).","triggerScenarios":"Calling `mastra studio deploy logs <deploy-id>` when the API call returns an error: invalid or expired token, deploy ID that does not exist, deploy belonging to another organization, or a server-side error surfaced via error.detail.","commonSituations":"Typo'd or stale deploy ID; logged-in account lacking access to the project's organization; expired CLI auth token; platform API returning 4xx/5xx details during incidents.","solutions":["Read the `error.detail` in the message — it states the server's specific reason; fix accordingly.","Re-authenticate (`mastra login` or equivalent) if the detail indicates auth/permission problems.","Verify the deploy ID is correct and belongs to your organization.","Retry later if the detail indicates a server-side (5xx) problem."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// verify auth and deploy ID before fetching\nconst projects = await fetchProjects(token, orgId);\nconst known = projects.some(p => p.latestDeployId === deployId);\nif (!known) throw new Error(`Deploy ${deployId} not found in org ${orgId}; check the ID and your login.`);","typeGuard":"function hasDetail(e: unknown): e is { detail: string } {\n  return typeof e === 'object' && e !== null && 'detail' in e && typeof (e as any).detail === 'string';\n}","tryCatchPattern":"try {\n  await getLogs(deployId, tail);\n} catch (err) {\n  if ((err as Error).message.startsWith('Failed to fetch logs:')) {\n    console.error(err.message); // server detail included\n    console.error('Re-authenticate (`mastra login`) or verify the deploy ID.');\n    return;\n  }\n  throw err;\n}","preventionTips":["Copy deploy IDs from command output rather than typing them.","Re-authenticate regularly to avoid expired tokens.","Confirm the deploy belongs to the organization you're logged into.","Check platform status before diagnosing as a local problem."],"tags":["cli","api","logs","network"],"backgroundTag":"api-fetch-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}