Skip to content

Commit 59886d2

Browse files
authored
Add better error checking to misc/convert-cache.py (#14909)
1 parent a6b5b1e commit 59886d2

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

misc/convert-cache.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from __future__ import annotations
99

1010
import os
11+
import re
1112
import sys
1213

1314
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@@ -36,15 +37,23 @@ def main() -> None:
3637

3738
input_dir = args.input_dir
3839
output_dir = args.output_dir or input_dir
40+
assert os.path.isdir(output_dir), f"{output_dir} is not a directory"
3941
if args.to_sqlite:
4042
input: MetadataStore = FilesystemMetadataStore(input_dir)
4143
output: MetadataStore = SqliteMetadataStore(output_dir)
4244
else:
45+
fnam = os.path.join(input_dir, "cache.db")
46+
msg = f"{fnam} does not exist"
47+
if not re.match(r"[0-9]+\.[0-9]+$", os.path.basename(input_dir)):
48+
msg += f" (are you missing Python version at the end, e.g. {input_dir}/3.11)"
49+
assert os.path.isfile(fnam), msg
4350
input, output = SqliteMetadataStore(input_dir), FilesystemMetadataStore(output_dir)
4451

4552
for s in input.list_all():
4653
if s.endswith(".json"):
47-
assert output.write(s, input.read(s), input.getmtime(s)), "Failed to write cache file!"
54+
assert output.write(
55+
s, input.read(s), input.getmtime(s)
56+
), f"Failed to write cache file {s}!"
4857
output.commit()
4958

5059

0 commit comments

Comments
 (0)