hcengineering/platform · warning · ApiError

Invalid format. Supported formats: ${supportedExportFormats.

Error message

Invalid format. Supported formats: ${supportedExportFormats.join(', ')}

What it means

parseExportFormat validates the caller-supplied format parameter against the explicitly supported list [ExportFormat.JSON, ExportFormat.CSV]. If format is not a string or not one of those values, it throws this 400 ApiError. Only formats actually implemented by WorkspaceExporter are allowed.

Source

Thrown at services/export/pod-export/src/server.ts:262

      url: wsLoginInfo.workspaceUrl
    }
    await fn(req, res, wsIds, token, wsLoginInfo.socialId, next)
  } catch (err: unknown) {
    next(err)
  }
}

const wrapRequest = (fn: AsyncRequestHandler) => (req: Request, res: Response, next: NextFunction) => {
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
  handleRequest(fn, req, res, next)
}

// Only formats actually supported by WorkspaceExporter
const supportedExportFormats: readonly ExportFormat[] = [ExportFormat.JSON, ExportFormat.CSV]

function parseExportFormat (rawFormat: unknown): ExportFormat {
  if (typeof rawFormat !== 'string' || !supportedExportFormats.includes(rawFormat as ExportFormat)) {
    throw new ApiError(400, `Invalid format. Supported formats: ${supportedExportFormats.join(', ')}`)
  }
  return rawFormat as ExportFormat
}

function toSafeFormatFileToken (format: ExportFormat): 'json' | 'csv' {
  switch (format) {
    case ExportFormat.JSON:
      return 'json'
    case ExportFormat.CSV:
      return 'csv'
    default:
      throw new ApiError(400, `Invalid format. Supported formats: ${supportedExportFormats.join(', ')}`)
  }
}

export function createServer (
  storageConfig: StorageConfiguration,
  dbUrl: string,

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Send format as exactly one of the supported values: json or csv.
  2. Check the ExportFormat enum values in your build and match the case exactly.
  3. Add client-side validation limiting the format picker to JSON/CSV.
  4. If you need another format, extend supportedExportFormats and WorkspaceExporter; you cannot get it via config alone.

Example fix

// before
fetch('/export', { method: 'POST', body: JSON.stringify({ _class, format: 'xlsx' }) })
// after
fetch('/export', { method: 'POST', body: JSON.stringify({ _class, format: 'csv' }) })
Defensive patterns

Strategy: validation

Validate before calling

const SUPPORTED = ['json', 'csv'] as const
if (typeof format !== 'string' || !SUPPORTED.includes(format as any)) {
  throw new Error(`Unsupported format: ${String(format)}. Use one of ${SUPPORTED.join(', ')}`)
}

Type guard

function isExportFormat(v: unknown): v is 'json' | 'csv' {
  return v === 'json' || v === 'csv'
}

Try / catch

try {
  await requestExport({ ...params, format })
} catch (e) {
  if (e instanceof ApiError && e.status === 400 && e.message.startsWith('Invalid format')) {
    return requestExport({ ...params, format: 'json' })
  }
  throw e
}

Prevention

When it happens

Trigger: Calling an export endpoint with ?format=xml, ?format=PDF, format omitted from the body/query (undefined), or a non-string value such as format: 123.

Common situations: Assuming other formats (XLSX, XML) are supported because the enum in shared code lists more values; typos in case ('JSON' vs 'json' if enum values are lowercase); clients upgraded to send a format the pod-export build predates.

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/7ac7bc7566c68a7e. Report an issue: GitHub.