hcengineering/platform · error

Failed to get metadata: ${err.message}

Error message

Failed to get metadata: ${err.message}

What it means

The image provider's metadata method calls getImageMetadata on the stored image path to build a thumbnail. Failures from getImageMetadata are wrapped and rethrown as 'Failed to get metadata: <err.message>'; the temp file is always cleaned up in finally.

Source

Thrown at pods/preview/src/providers/image.ts:77

    return { mimeType: contentType, filePath: path }
  }

  async metadata (
    ctx: MeasureContext,
    workspace: WorkspaceUuid,
    name: string,
    contentType: string
  ): Promise<PreviewMetadata> {
    const { filePath: path } = await ctx.with('image', { contentType }, (ctx) => {
      return this.image(ctx, workspace, name, contentType)
    })

    try {
      const thumbnail = await getImageMetadata(ctx, path)
      return { thumbnail }
    } catch (err: any) {
      throw new Error(`Failed to get metadata: ${err.message}`)
    } finally {
      this.tempDir.rm(path)
    }
  }
}

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Inspect the inner err.message in 'Failed to get metadata: ...' for the concrete cause
  2. Validate the upload is a real image (magic-byte sniffing) before preview processing
  3. Convert unsupported formats (e.g. HEIC) to JPEG/PNG before preview
  4. Check available temp disk space and that the image processing dependencies are installed
Defensive patterns

Strategy: fallback

Validate before calling

if (!(await hasValidImageMagicBytes(path))) {
  // treat as non-image: skip preview generation
}

Type guard

function isPreviewableImage (meta: { mime?: string; size?: number }): boolean {
  const ok = ['image/jpeg', 'image/png', 'image/gif', 'image/webp']
  return typeof meta?.mime === 'string' && ok.includes(meta.mime) && (meta.size ?? 0) > 0
}

Try / catch

try {
  const { thumbnail } = await imageProvider.metadata(ctx, file)
} catch (err) {
  ctx.warn('image preview failed', { cause: err.message })
  return { thumbnail: genericImagePlaceholder }
}

Prevention

When it happens

Trigger: metadata() on an image when getImageMetadata throws — invalid/unsupported image data, truncated file, unsupported format by the processing library, or IO errors on the temp path.

Common situations: Users upload files that aren't actually valid images (wrong extension); unsupported formats (HEIC, exotic TIFFs); zero-byte or truncated uploads; image library lacking format support.

Related errors


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