Procházet zdrojové kódy

gracefully exit when given invalid dates

pull/287/head
nicfb před 3 roky
rodič
revize
1a030864af
2 změnil soubory, kde provedl 6 přidání a 28 odebrání
  1. +5
    -14
      kosmorro/__main__.py
  2. +1
    -14
      kosmorro/exceptions.py

+ 5
- 14
kosmorro/__main__.py Zobrazit soubor

@@ -135,6 +135,10 @@ def run():
use_colors, use_colors,
args.show_graph, args.show_graph,
) )
except InvalidDateRangeError as error:
print_stderr(colored(error, "red"))
debug.debug_print(error)
return 6
except SearchDatesNotGivenError as error: except SearchDatesNotGivenError as error:
print_stderr(colored(error.msg, "red")) print_stderr(colored(error.msg, "red"))
debug.debug_print(error) debug.debug_print(error)
@@ -270,23 +274,10 @@ def get_search_information(
show_graph=show_graph, show_graph=show_graph,
search_enabled=True, 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: except KeyError as error:
raise InvalidOutputFormatError(output_format, list(get_dumpers().keys())) raise InvalidOutputFormatError(output_format, list(get_dumpers().keys()))
except OutOfRangeDateError as error: 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}: def get_dumpers() -> {str: dumper.Dumper}:


+ 1
- 14
kosmorro/exceptions.py Zobrazit soubor

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






Načítá se…
Zrušit
Uložit