diff --git a/tools/doc_census_check.py b/tools/doc_census_check.py index 1574ae3..bc26980 100644 --- a/tools/doc_census_check.py +++ b/tools/doc_census_check.py @@ -1828,10 +1828,15 @@ def main(): units[name].update(k for k in entry[0][0] if k in keep) observed = sum(len(v) for v in seen.values()) kept = sum(len(v) for v in units.values()) - with open(a.save_vocab, "w", encoding="utf-8") as fh: - json.dump({"rev": a.rev, "repo": a.repo, - "tools": {k: sorted(v) for k, v in units.items()}}, - fh, indent=1, sort_keys=True) + try: + with open(a.save_vocab, "w", encoding="utf-8") as fh: + json.dump({"rev": a.rev, "repo": a.repo, + "tools": {k: sorted(v) for k, v in units.items()}}, + fh, indent=1, sort_keys=True) + except OSError as exc: + print("cannot write --save-vocab " + a.save_vocab + ": " + str(exc), + file=sys.stderr) + return 2 print(f"wrote vocabulary {a.save_vocab}: {len(units)} tool(s), " f"{kept} unit(s) at {a.rev} ({observed} key(s) observed, " f"{observed - kept} unspendable by any claim)") diff --git a/tools/queue_index.py b/tools/queue_index.py index 698b23f..844818b 100644 --- a/tools/queue_index.py +++ b/tools/queue_index.py @@ -578,8 +578,12 @@ def run(args): return 0 if args.write: - with open(args.write, "w", encoding="utf-8") as fh: - fh.write(build_doc(payload)) + try: + with open(args.write, "w", encoding="utf-8") as fh: + fh.write(build_doc(payload)) + except OSError as exc: + print("cannot write --write " + args.write + ": " + str(exc), file=sys.stderr) + return 2 print("wrote %s (%d bytes)" % (args.write, os.path.getsize(args.write))) return 0 diff --git a/tools/tool_map.py b/tools/tool_map.py index 2699e5f..a58926d 100644 --- a/tools/tool_map.py +++ b/tools/tool_map.py @@ -507,8 +507,12 @@ def main(): print(f"tool_map: wrote {args.json}") if args.write: - with open(args.write, "w", encoding="utf-8") as fh: - fh.write(text) + try: + with open(args.write, "w", encoding="utf-8") as fh: + fh.write(text) + except OSError as exc: + print("cannot write --write " + args.write + ": " + str(exc), file=sys.stderr) + return 2 print(f"tool_map: wrote {args.write} ({len(text)} B, " f"{len(data['rows'])} tools, {len(data['legs'])} gate legs)") return 0