{"record":{"id":"bf3c9322ec147c99","repo":"hcengineering/platform","slug":"failed-to-delete-file","errorCode":null,"errorMessage":"Failed to delete file","messagePattern":"Failed to delete file","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"foundations/core/packages/storage-client/src/client/datalake.ts","lineNumber":71,"sourceCode":"      if (response.ok) {\n        return await response.json()\n      }\n    } catch (err: any) {}\n    return {}\n  }\n\n  async deleteFile (token: string, workspace: string, file: string): Promise<void> {\n    const url = this.getFileUrl(workspace, file)\n\n    const response = await fetch(url, {\n      method: 'DELETE',\n      headers: {\n        Authorization: `Bearer ${token}`\n      }\n    })\n\n    if (!response.ok) {\n      throw new Error('Failed to delete file')\n    }\n  }\n\n  async uploadFile (\n    token: string,\n    workspace: string,\n    uuid: string,\n    file: File,\n    options?: FileStorageUploadOptions\n  ): Promise<void> {\n    if (file.size <= 10 * 1024 * 1024) {\n      const formData = new FormData()\n      formData.append('file', file, uuid)\n\n      await uploadXhr(\n        {\n          url: concatLink(this.baseUrl, `/upload/form-data/${encodeURIComponent(workspace)}`),\n          method: 'POST',","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/foundations/core/packages/storage-client/src/client/datalake.ts#L53-L89","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nawait storage.deleteFile(token, workspace, file)\n\n// after: confirm the file exists and handle missing gracefully\nconst meta = await storage.getFileMeta(token, workspace, file)\nif (Object.keys(meta).length > 0) {\n  try { await storage.deleteFile(token, workspace, file) }\n  catch { /* inspect status / re-auth and retry */ }\n}","handlingStrategy":"try-catch","validationCode":"// pre-check before delete\nconst meta = await storage.getFileMeta(token, workspace, file)\nif (meta === undefined || Object.keys(meta).length === 0) return // nothing to delete\nif (token === undefined || token.split('.').length !== 2 && !token.startsWith('ey')) console.warn('token looks malformed')","typeGuard":"null","tryCatchPattern":"try {\n  await storage.deleteFile(token, workspace, file)\n} catch (err) {\n  if (err instanceof Error && err.message === 'Failed to delete file') {\n    // inspect status by retrying with fetch and reading response.status, or re-auth once\n  } else throw err\n}","preventionTips":["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."],"tags":["storage","http","network","delete"],"backgroundTag":"storage-delete-request-failed","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}