hcengineering/platform · error

Failed to delete file

Error message

Failed to delete file

What it means

The front-style storage client's deleteFile sends DELETE <baseUrl>/blob/<workspace>/<file> with a Bearer token and throws this generic Error whenever response.ok is false. As with the other storage clients, the status code and response body are dropped, so the message is intentionally opaque.

Source

Thrown at foundations/core/packages/storage-client/src/client/front.ts:58

    return getPathname(url)
  }

  async getFileMeta (token: string, workspace: string, file: string): Promise<Record<string, any>> {
    return {}
  }

  async deleteFile (token: string, workspace: string, file: string): Promise<void> {
    const url = this.getFileUrl(workspace, file)

    const response = await fetch(url, {
      method: 'DELETE',
      headers: {
        Authorization: `Bearer ${token}`
      }
    })

    if (!response.ok) {
      throw new Error('Failed to delete file')
    }
  }

  async uploadFile (
    token: string,
    workspace: string,
    uuid: string,
    file: File,
    options?: FileStorageUploadOptions
  ): Promise<void> {
    const formData = new FormData()
    formData.append('file', file, uuid)

    await uploadXhr(
      {
        url: concatLink(this.baseUrl, `/${workspace}`),
        method: 'POST',
        headers: { Authorization: `Bearer ${token}` },

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Capture response.status at the throw site (or via a proxy of the client) to identify the failure class.
  2. Refresh the authorization token and retry the delete once.
  3. Validate the file UUID exists via the metadata API before deleting to avoid 404 noise.
  4. Check the storage service health and that the configured baseUrl routes to it.

Example fix

// before
await storage.deleteFile(staleToken, workspace, uuid) // throws 'Failed to delete file' on 401

// after
const fresh = await renewToken()
await storage.deleteFile(fresh, workspace, uuid)
Defensive patterns

Strategy: try-catch

Validate before calling

// guard inputs before calling deleteFile
if (token === undefined || token.length === 0) throw new Error('Missing storage token')
if (workspace === undefined || file === undefined) throw new Error('workspace and file uuid are required')

Type guard

null

Try / catch

try {
  await storage.deleteFile(token, workspace, file)
} catch (err) {
  if (err instanceof Error && err.message === 'Failed to delete file') {
    // refresh token once and retry; if it fails again, surface to user
    await storage.deleteFile(await refreshToken(), workspace, file)
  } else throw err
}

Prevention

When it happens

Trigger: deleteFile(token, workspace, file) gets 401 (expired Bearer token), 403 (no permission on workspace), 404 (file UUID or workspace wrong), or 5xx from the storage service.

Common situations: Session expired while a bulk cleanup job was running; deleting attachments of an object that was already removed; front storage service scaled down or its ingress misrouting /blob paths; baseUrl pointing to the frontend instead of the storage service.

Related errors


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