We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
`DigestEntries` returns a `Directory` instead of an empty vector for non-matching digest


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/python/pants/jvm/util_rules.py`
Content:
```
1 # Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).
2 # Licensed under the Apache License, Version 2.0 (see LICENSE).
3 
4 from __future__ import annotations
5 
6 from dataclasses import dataclass
7 
8 from pants.engine.fs import Digest, DigestEntries, DigestSubset, FileDigest, FileEntry, PathGlobs
9 from pants.engine.rules import Get, collect_rules, rule
10 
11 
12 @dataclass(frozen=True)
13 class ExtractFileDigest:
14     digest: Digest
15     file_path: str
16 
17 
18 @rule
19 async def digest_to_file_digest(request: ExtractFileDigest) -> FileDigest:
20     digest = await Get(Digest, DigestSubset(request.digest, PathGlobs([request.file_path])))
21     files_or_directories = await Get(DigestEntries, Digest, digest)
22     digest_entries = [entry for entry in files_or_directories if isinstance(entry, FileEntry)]
23 
24     if len(digest_entries) == 0:
25         raise Exception(f"ExtractFileDigest: '{request.file_path}' not found in {request.digest}.")
26     elif len(digest_entries) > 1:
27         raise Exception(
28             f"ExtractFileDigest: Unexpected error: '{request.file_path}' found multiple times in {request.digest}"
29         )
30 
31     file_info = digest_entries[0]
32     return file_info.file_digest
33 
34 
35 def rules():
36     return [*collect_rules()]
37
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/python/pants/jvm/util_rules.py b/src/python/pants/jvm/util_rules.py
--- a/src/python/pants/jvm/util_rules.py
+++ b/src/python/pants/jvm/util_rules.py
@@ -18,8 +18,7 @@
 @rule
 async def digest_to_file_digest(request: ExtractFileDigest) -> FileDigest:
     digest = await Get(Digest, DigestSubset(request.digest, PathGlobs([request.file_path])))
-    files_or_directories = await Get(DigestEntries, Digest, digest)
-    digest_entries = [entry for entry in files_or_directories if isinstance(entry, FileEntry)]
+    digest_entries = await Get(DigestEntries, Digest, digest)
 
     if len(digest_entries) == 0:
         raise Exception(f"ExtractFileDigest: '{request.file_path}' not found in {request.digest}.")
@@ -29,6 +28,12 @@
         )
 
     file_info = digest_entries[0]
+
+    if not isinstance(file_info, FileEntry):
+        raise AssertionError(
+            f"Unexpected error: '{request.file_path}' refers to a directory, not a file."
+        )
+
     return file_info.file_digest

{"golden_diff": "diff --git a/src/python/pants/jvm/util_rules.py b/src/python/pants/jvm/util_rules.py\n--- a/src/python/pants/jvm/util_rules.py\n+++ b/src/python/pants/jvm/util_rules.py\n@@ -18,8 +18,7 @@\n @rule\n async def digest_to_file_digest(request: ExtractFileDigest) -> FileDigest:\n     digest = await Get(Digest, DigestSubset(request.digest, PathGlobs([request.file_path])))\n-    files_or_directories = await Get(DigestEntries, Digest, digest)\n-    digest_entries = [entry for entry in files_or_directories if isinstance(entry, FileEntry)]\n+    digest_entries = await Get(DigestEntries, Digest, digest)\n \n     if len(digest_entries) == 0:\n         raise Exception(f\"ExtractFileDigest: '{request.file_path}' not found in {request.digest}.\")\n@@ -29,6 +28,12 @@\n         )\n \n     file_info = digest_entries[0]\n+\n+    if not isinstance(file_info, FileEntry):\n+        raise AssertionError(\n+            f\"Unexpected error: '{request.file_path}' refers to a directory, not a file.\"\n+        )\n+\n     return file_info.file_digest\n", "issue": "`DigestEntries` returns a `Directory` instead of an empty vector for non-matching digest\n\n", "before_files": [{"content": "# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).\n# Licensed under the Apache License, Version 2.0 (see LICENSE).\n\nfrom __future__ import annotations\n\nfrom dataclasses import dataclass\n\nfrom pants.engine.fs import Digest, DigestEntries, DigestSubset, FileDigest, FileEntry, PathGlobs\nfrom pants.engine.rules import Get, collect_rules, rule\n\n\n@dataclass(frozen=True)\nclass ExtractFileDigest:\n    digest: Digest\n    file_path: str\n\n\n@rule\nasync def digest_to_file_digest(request: ExtractFileDigest) -> FileDigest:\n    digest = await Get(Digest, DigestSubset(request.digest, PathGlobs([request.file_path])))\n    files_or_directories = await Get(DigestEntries, Digest, digest)\n    digest_entries = [entry for entry in files_or_directories if isinstance(entry, FileEntry)]\n\n    if len(digest_entries) == 0:\n        raise Exception(f\"ExtractFileDigest: '{request.file_path}' not found in {request.digest}.\")\n    elif len(digest_entries) > 1:\n        raise Exception(\n            f\"ExtractFileDigest: Unexpected error: '{request.file_path}' found multiple times in {request.digest}\"\n        )\n\n    file_info = digest_entries[0]\n    return file_info.file_digest\n\n\ndef rules():\n    return [*collect_rules()]\n", "path": "src/python/pants/jvm/util_rules.py"}], "after_files": [{"content": "# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).\n# Licensed under the Apache License, Version 2.0 (see LICENSE).\n\nfrom __future__ import annotations\n\nfrom dataclasses import dataclass\n\nfrom pants.engine.fs import Digest, DigestEntries, DigestSubset, FileDigest, FileEntry, PathGlobs\nfrom pants.engine.rules import Get, collect_rules, rule\n\n\n@dataclass(frozen=True)\nclass ExtractFileDigest:\n    digest: Digest\n    file_path: str\n\n\n@rule\nasync def digest_to_file_digest(request: ExtractFileDigest) -> FileDigest:\n    digest = await Get(Digest, DigestSubset(request.digest, PathGlobs([request.file_path])))\n    digest_entries = await Get(DigestEntries, Digest, digest)\n\n    if len(digest_entries) == 0:\n        raise Exception(f\"ExtractFileDigest: '{request.file_path}' not found in {request.digest}.\")\n    elif len(digest_entries) > 1:\n        raise Exception(\n            f\"ExtractFileDigest: Unexpected error: '{request.file_path}' found multiple times in {request.digest}\"\n        )\n\n    file_info = digest_entries[0]\n\n    if not isinstance(file_info, FileEntry):\n        raise AssertionError(\n            f\"Unexpected error: '{request.file_path}' refers to a directory, not a file.\"\n        )\n\n    return file_info.file_digest\n\n\ndef rules():\n    return [*collect_rules()]\n", "path": "src/python/pants/jvm/util_rules.py"}]}