Преглед изворни кода

gracefully exit when given invalid dates

pull/287/head
nicfb пре 1 година
родитељ
комит
1a030864af
2 измењених фајлова са 6 додато и 28 уклоњено
  1. +5
    -14
      kosmorro/__main__.py
  2. +1
    -14
      kosmorro/exceptions.py

+ 5
- 14
kosmorro/__main__.py Прегледај датотеку

@@ -135,6 +135,10 @@ def run():
use_colors,
args.show_graph,
)
except InvalidDateRangeError as error:
print_stderr(colored(error, "red"))
debug.debug_print(error)
return 6
except SearchDatesNotGivenError as error:
print_stderr(colored(error.msg, "red"))
debug.debug_print(error)
@@ -270,23 +274,10 @@ def get_search_information(
show_graph=show_graph,
search_enabled=True,
)
except InvalidDateRangeError as error:
print(
colored(
_(
"Search start date {start_search} must be before end date {end_search}"
).format(
start_search=format_date(error.start_date, "long"),
end_search=format_date(error.end_date, "long"),
),
"red",
)
)
except KeyError as error:
raise InvalidOutputFormatError(output_format, list(get_dumpers().keys()))
except OutOfRangeDateError as error:
print(colored(error.msg, "red"))
debug.debug_print(error)
raise DateRangeError(error.min_date, error.max_date)


def get_dumpers() -> {str: dumper.Dumper}:


+ 1
- 14
kosmorro/exceptions.py Прегледај датотеку

@@ -40,19 +40,6 @@ class OutOfRangeDateError(RuntimeError):
)


class InvalidDateRangeError(RuntimeError):
def __init__(self, start_date: date, end_date: date):
super().__init__()
self.start_date = start_date
self.end_date = end_date
self.msg = _(
"The start date {starting_date} must be before the end date {ending_date}"
).format(
starting_date=format_date(start_date, "long"),
ending_date=format_date(end_date, "long"),
)


class InvalidOutputFormatError(RuntimeError):
def __init__(self, output_format: str, accepted_extensions: [str]):
super().__init__()
@@ -70,7 +57,7 @@ class SearchDatesNotGivenError(RuntimeError):
def __init__(self):
super().__init__()
self.msg = _(
"Search end date (--until) is required when searching events.'"
"Search end date (--until) is required when searching events."
)




Loading…
Откажи
Сачувај