From a8b358c5e5b34b9a51a5829f5b9e7fadbcd003e4 Mon Sep 17 00:00:00 2001 From: Richard Darst Date: Sun, 23 Jan 2022 02:33:28 +0200 Subject: [PATCH] Print error messages to stderr, not stdout - print(..., file=sys.stderr) for error messages - Provides better error handling if the output is being directed to a file - Review: general check --- yaml2ics.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/yaml2ics.py b/yaml2ics.py index 133e677..9d88051 100644 --- a/yaml2ics.py +++ b/yaml2ics.py @@ -43,16 +43,16 @@ def event_from_yaml(event_yaml: dict) -> ics.Event: interval = repeat['interval'] if not len(interval) == 1: - print('Error: interval must specify seconds, minutes, hours, days, weeks, months, or years only') + print('Error: interval must specify seconds, minutes, hours, days, weeks, months, or years only', file=sys.stderr) sys.exit(-1) interval_measure = list(interval.keys())[0] if interval_measure not in interval_type: - print('Error: expected interval to be specified in seconds, minutes, hours, days, weeks, months, or years only') + print('Error: expected interval to be specified in seconds, minutes, hours, days, weeks, months, or years only', file=sys.stderr) sys.exit(-1) if 'until' not in repeat: - print('Error: must specify end date for repeating events') + print('Error: must specify end date for repeating events', file=sys.stderr) sys.exit(-1) event.end = d.get('end', None) @@ -102,7 +102,7 @@ def files_to_calendar(files: list) -> ics.Calendar: files = sys.argv[1:] for f in files: if not os.path.isfile(f): - print(f'Error: {f} is not a file') + print(f'Error: {f} is not a file', file=sys.stderr) sys.exit(-1) calendar = files_to_calendar(files)