{"record":{"id":"727ca57908ed0754","repo":"apache/beam","slug":"error-trying-to-delete-s-s","errorCode":null,"errorMessage":"Error trying to delete %s: %s","messagePattern":"Error trying to delete (.+?): (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/util/GcsUtilV1.java","lineNumber":1407,"sourceCode":"\n  private void enqueueDelete(final GcsPath file, BatchInterface batch) throws IOException {\n    Storage.Objects.Delete deleteRequest =\n        storageClient.objects().delete(file.getBucket(), file.getObject());\n    batch.queue(\n        deleteRequest,\n        new JsonBatchCallback<Void>() {\n          @Override\n          public void onSuccess(Void obj, HttpHeaders responseHeaders) {\n            LOG.debug(\"Successfully deleted {}\", file);\n          }\n\n          @Override\n          public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) throws IOException {\n            if (e.getCode() == 404) {\n              LOG.info(\n                  \"Ignoring failed deletion of file {} which already does not exist: {}\", file, e);\n            } else {\n              throw new IOException(String.format(\"Error trying to delete %s: %s\", file, e));\n            }\n          }\n        });\n  }\n\n  @VisibleForTesting\n  interface BatchInterface {\n    <T> void queue(AbstractGoogleJsonClientRequest<T> request, JsonBatchCallback<T> cb)\n        throws IOException;\n\n    void execute() throws IOException;\n\n    int size();\n  }\n}\n","sourceCodeStart":1389,"sourceCodeEnd":1423,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/util/GcsUtilV1.java#L1389-L1423","documentation":"Thrown by GcsUtilV1's async delete callback when a GCS object deletion fails with any error other than 404 (404s are logged and ignored since the file already doesn't exist). The message embeds the target path and the full GoogleJsonError.","triggerScenarios":"Calling GcsUtilV1.remove (batched object deletion); the GCS JSON API returns a non-404 error for one object, e.g. 403 permission denied, 429 rate limit, or 5xx.","commonSituations":"Cleaning up temporary/staging files during pipeline teardown with credentials lacking storage.objects.delete permission; hitting GCS rate limits when deleting thousands of objects; object under retention/hold policies.","solutions":["Read the embedded GoogleJsonError code: 403 means grant storage.objects.delete (or storage.admin) to the credential.","For 429/5xx, retry the deletion later or reduce deletion concurrency.","Verify the object isn't protected by a retention policy, event-based hold, or bucket policy.","If the file is expected to possibly not exist, no action needed for 404 — it's already ignored."],"exampleFix":"// before: single service account with read-only access deletes temp files\n// after: grant delete permission\n//   gcloud projects add-iam-policy-binding PROJECT \\\n//     --member=serviceAccount:SA --role=roles/storage.objectAdmin","handlingStrategy":"try-catch","validationCode":"// verify delete permission ahead of teardown\n// gcloud storage objects list gs://bucket --format=... requires objectViewer;\n// deletion additionally requires roles/storage.objectAdmin or objectCreator+delete","typeGuard":null,"tryCatchPattern":"try {\n  gcsUtil.remove(ImmutableList.of(path));\n} catch (IOException e) {\n  if (e.getMessage().startsWith(\"Error trying to delete\")) {\n    // inspect embedded GoogleJsonError code: 403 fix IAM, 429/5xx retry\n  }\n}","preventionTips":["Grant storage.objects.delete (objectAdmin) to the credential used for cleanup","Throttle bulk deletions to avoid 429 rate limits","Check retention policies/holds on objects that must be deleted"],"tags":["gcs","delete","io","http-error","java","apache-beam"],"backgroundTag":"http-error-response","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}