mastra-ai/mastra · error · Error

Failed to fetch logs: ${error.detail}

Error message

Failed to fetch logs: ${error.detail}

What it means

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.).

Source

Thrown at packages/cli/src/commands/studio/deploy-logs.ts:15

import { writeBarLine } from '../../utils/clack-bar.js';
import { authHeaders, createApiClient, MASTRA_PLATFORM_API_URL, platformFetch } from '../auth/client.js';
import { getToken, getCurrentOrgId, validateOrgAccess } from '../auth/credentials.js';

async function getLogs(deployId: string, tail: string | undefined, token: string, orgId: string) {
  const client = createApiClient(token, orgId);
  const { data, error } = await client.GET('/v1/studio/deploys/{id}/logs', {
    params: {
      path: { id: deployId },
      query: tail ? { tail } : undefined,
    },
  });

  if (error) {
    throw new Error(`Failed to fetch logs: ${error.detail}`);
  }

  if (data.logs) {
    for (const line of data.logs.split('\n')) {
      if (line) await writeBarLine(line);
    }
  } else {
    console.info('(no logs available)');
  }
}

async function streamLogs(deployId: string, token: string, orgId: string) {
  const url = `${MASTRA_PLATFORM_API_URL}/v1/studio/deploys/${deployId}/logs/stream`;

  const resp = await platformFetch(url, {
    headers: {
      ...authHeaders(token, orgId),
      Accept: 'text/event-stream',

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Read the `error.detail` in the message — it states the server's specific reason; fix accordingly.
  2. Re-authenticate (`mastra login` or equivalent) if the detail indicates auth/permission problems.
  3. Verify the deploy ID is correct and belongs to your organization.
  4. Retry later if the detail indicates a server-side (5xx) problem.
Defensive patterns

Strategy: try-catch

Validate before calling

// verify auth and deploy ID before fetching
const projects = await fetchProjects(token, orgId);
const known = projects.some(p => p.latestDeployId === deployId);
if (!known) throw new Error(`Deploy ${deployId} not found in org ${orgId}; check the ID and your login.`);

Type guard

function hasDetail(e: unknown): e is { detail: string } {
  return typeof e === 'object' && e !== null && 'detail' in e && typeof (e as any).detail === 'string';
}

Try / catch

try {
  await getLogs(deployId, tail);
} catch (err) {
  if ((err as Error).message.startsWith('Failed to fetch logs:')) {
    console.error(err.message); // server detail included
    console.error('Re-authenticate (`mastra login`) or verify the deploy ID.');
    return;
  }
  throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/618c763b5a822f9e. Report an issue: GitHub.