Skip to content

Commit 6b64a79

Browse files
author
Charles Parker
committed
Added output file check to fail if the output file already exists. Otherwise, create an empty file as UTF-8. Partially addresses Issue #24.
1 parent 4761d19 commit 6b64a79

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/metacoder/metacoder.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import sys
23
from pathlib import Path
34
from typing import Optional, Union
45

@@ -543,6 +544,17 @@ def eval_command(config: str, output: str, workdir: str, coders: tuple, verbose:
543544
output_path = Path(output)
544545
workdir_path = Path(workdir)
545546

547+
try:
548+
# Create the output file only if it doesn't exist; fail if it does
549+
with output_path.open("x", encoding="utf-8") as _:
550+
pass
551+
except FileExistsError:
552+
print(
553+
f"Error: '{output_path}' already exists. Please delete it or specify a different filename.",
554+
file=sys.stderr,
555+
)
556+
sys.exit(1)
557+
546558
# Convert coders tuple to list (empty tuple if not specified)
547559
coders_list = list(coders) if coders else None
548560

0 commit comments

Comments
 (0)