hcengineering/platform · error
Failed to delete file
Error message
Failed to delete file
What it means
DatalakeStorage.deleteFile issues a DELETE to `<baseUrl>/blob/<workspace>/<file>` with a Bearer token and throws this generic Error when the HTTP response is not ok. The client discards the status code and body, so the message alone does not tell you whether it was 401, 403, 404 or 5xx.
Source
Thrown at foundations/core/packages/storage-client/src/client/datalake.ts:71
if (response.ok) {
return await response.json()
}
} catch (err: 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> {
if (file.size <= 10 * 1024 * 1024) {
const formData = new FormData()
formData.append('file', file, uuid)
await uploadXhr(
{
url: concatLink(this.baseUrl, `/upload/form-data/${encodeURIComponent(workspace)}`),
method: 'POST',View on GitHub (pinned to 63e28dc964)
Solutions
- Check the actual HTTP status: temporarily log response.status (or patch deleteFile) to distinguish 401/403/404/5xx.
- Verify the token is valid and not expired; re-acquire it and retry once.
- Confirm the workspace and file UUID exist (e.g. call getFileMeta first) before deleting.
- Verify the storage service is healthy and the baseUrl configuration is correct for the environment.
Example fix
// before
await storage.deleteFile(token, workspace, file)
// after: confirm the file exists and handle missing gracefully
const meta = await storage.getFileMeta(token, workspace, file)
if (Object.keys(meta).length > 0) {
try { await storage.deleteFile(token, workspace, file) }
catch { /* inspect status / re-auth and retry */ }
} Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check before delete
const meta = await storage.getFileMeta(token, workspace, file)
if (meta === undefined || Object.keys(meta).length === 0) return // nothing to delete
if (token === undefined || token.split('.').length !== 2 && !token.startsWith('ey')) console.warn('token looks malformed') Type guard
null
Try / catch
try {
await storage.deleteFile(token, workspace, file)
} catch (err) {
if (err instanceof Error && err.message === 'Failed to delete file') {
// inspect status by retrying with fetch and reading response.status, or re-auth once
} else throw err
} Prevention
- Refresh tokens before long batch-delete operations.
- Check file existence via getFileMeta before deleting to avoid 404 noise.
- Validate workspace/uuid values come from trusted records, not user input.
- Monitor the storage service health endpoint in the deployment.
When it happens
Trigger: deleteFile(token, workspace, file) receives a non-2xx response: expired/invalid token, wrong workspace name, unknown file UUID, storage service returning 500/503, or a proxy blocking the DELETE method.
Common situations: Token refreshed elsewhere but a stale one captured in the caller; deleting a file that was already removed (404); misconfigured DatalakeStorage baseUrl pointing at the wrong service or path prefix; corporate proxy stripping DELETE bodies or blocking CORS preflight for DELETE.
Related errors
- Failed to delete file
- Failed to delete file
- response.statusText
- Failed to fetch config
- unknownError(response.statusText)
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/bf3c9322ec147c99.
Report an issue: GitHub.