hcengineering/platform · error

Failed to get metadata: ${err.message}

Error message

Failed to get metadata: ${err.message}

What it means

The video provider's metadata() extracts a thumbnail frame from the video (via image()) and then reads the resulting PNG's dimensions with getImageMetadata (sharp). This error wraps any failure of that read — typically the frame extraction failed so the file is missing/invalid, or sharp cannot parse the produced image. The underlying err.message is appended.

Source

Thrown at pods/preview/src/providers/video.ts:67

    return { mimeType: 'image/png', filePath: pngFile }
  }

  async metadata (
    ctx: MeasureContext,
    workspace: WorkspaceUuid,
    name: string,
    contentType: string
  ): Promise<PreviewMetadata> {
    const { filePath: path } = await ctx.with('thumbnail', {}, (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. Check the wrapped err.message to distinguish 'file not found' (extraction failed) from 'unsupported image format'.
  2. Install/verify ffmpeg on the preview host so video frame extraction succeeds.
  3. Verify the video plays/has a decodable first frame; re-upload a valid file if corrupted.
  4. Check disk space and temp file permissions.

Example fix

// before
throw new Error(`Failed to get metadata: ${err.message}`)
// after
ctx.error('video metadata failed', { cause: err.message })
throw new Error(`Failed to get metadata: ${err.message}`)
Defensive patterns

Strategy: try-catch

Validate before calling

const stat = await storage.stat(ctx, { uuid: workspace }, name)
if (stat === undefined || !stat.contentType.startsWith('video/')) return null

Type guard

function isVideoBlob(stat): stat is Blob {
  return stat != null && typeof stat.contentType === 'string' && stat.contentType.startsWith('video/')
}

Try / catch

try {
  const meta = await preview.metadata(ctx, workspace, name)
} catch (err) {
  if (String(err.message).startsWith('Failed to get metadata:')) {
    ctx.warn('video preview metadata unavailable', { name, cause: err.message })
    return { thumbnail: undefined }
  }
  throw err
}

Prevention

When it happens

Trigger: Requesting metadata for a video blob whose thumbnail frame could not be extracted (unsupported codec, ffmpeg missing or failed, zero-length video), yielding a missing or corrupt temp image passed to sharp.

Common situations: Host without ffmpeg on PATH, exotic codecs (e.g. HEVC/AV1) ffmpeg build can't decode, corrupted uploads, disk-full producing truncated frame files.

Related errors


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