{"record":{"id":"f6bb5a251bc2021e","repo":"apache/beam","slug":"the-resource-to-delete-does-not-exist","errorCode":null,"errorMessage":"The resource to delete does not exist.","messagePattern":"The resource to delete does not exist\\.","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/azure/src/main/java/org/apache/beam/sdk/io/azure/blobstore/AzureBlobStoreFileSystem.java","lineNumber":422,"sourceCode":"    delete(srcResourceIds);\n  }\n\n  /** This method will delete a virtual folder or a blob, not a container. */\n  @Override\n  protected void delete(Collection<AzfsResourceId> resourceIds) throws IOException {\n    for (AzfsResourceId resourceId : resourceIds) {\n      if (resourceId.getBlob() == null) {\n        throw new IOException(\"delete does not delete containers.\");\n      }\n\n      BlobContainerClient container =\n          client.get().getBlobContainerClient(resourceId.getContainer());\n\n      // deleting a blob that is not a directory\n      if (!resourceId.isDirectory()) {\n        BlobClient blob = container.getBlobClient(resourceId.getBlob());\n        if (!blob.exists()) {\n          throw new FileNotFoundException(\"The resource to delete does not exist.\");\n        }\n        blob.delete();\n      }\n\n      // deleting a directory (not a container)\n      else {\n        PagedIterable<BlobItem> blobsInDirectory =\n            container.listBlobsByHierarchy(resourceId.getBlob());\n        blobsInDirectory.forEach(\n            blob -> {\n              String blobName = blob.getName();\n              container.getBlobClient(blobName).delete();\n            });\n      }\n    }\n  }\n\n  @Override","sourceCodeStart":404,"sourceCodeEnd":440,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/azure/src/main/java/org/apache/beam/sdk/io/azure/blobstore/AzureBlobStoreFileSystem.java#L404-L440","documentation":"When deleting a non-directory resource, delete() verifies the blob exists via blobClient.exists() and throws FileNotFoundException with this message if it does not. Azure's blob.delete() is idempotent, but Beam's filesystem contract treats deleting a nonexistent resource as an error, so the check happens before the delete call.","triggerScenarios":"Calling FileSystems.delete() (directly or via rename()'s delete step) with an azfs blob path that no longer exists in the container.","commonSituations":"rename() failing at the delete stage after copy succeeded because another process removed the source; double-cleanup code deleting the same paths twice; lifecycle policies deleting blobs before your cleanup job runs; case-sensitive key mismatch.","solutions":["Match the paths first with FileSystems.match() and delete only resources that exist (make cleanup idempotent).","Wrap the delete in try-catch for FileNotFoundException and treat it as success when cleanup semantics allow.","Fix the blob key spelling/casing.","Avoid deleting the same source list twice (e.g. after an earlier rename already moved it)."],"exampleFix":"// before\nFileSystems.delete(ImmutableList.of(FileSystems.matchNewResource(\"azfs://c/gone.txt\", false))); // throws\n// after\nMatchResult m = FileSystems.match(\"azfs://c/gone.txt\");\nif (m.status() == MatchResult.Status.OK && !m.metadata().isEmpty()) {\n  FileSystems.delete(m.metadata().stream().map(MatchResult.Metadata::resourceId).collect(ImmutableList.toImmutableList()));\n}","handlingStrategy":"try-catch","validationCode":"MatchResult m = FileSystems.match(path);\nif (m.status() == MatchResult.Status.OK) {\n  FileSystems.delete(m.metadata().stream().map(MatchResult.Metadata::resourceId).collect(ImmutableList.toImmutableList()));\n}","typeGuard":null,"tryCatchPattern":"try {\n  FileSystems.delete(ids);\n} catch (FileNotFoundException e) {\n  LOG.info(\"already deleted, ignoring: {}\", e.getMessage());\n}","preventionTips":["Make cleanup idempotent: match-then-delete or swallow FileNotFoundException.","Never delete the same resource list twice (e.g. after rename already moved it).","Be aware blob keys are case-sensitive when constructing delete paths."],"tags":["azure","blob-storage","file-not-found","delete","io"],"backgroundTag":"file-not-found","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}