Skip to content

Commit

Permalink
Error on accessing invalid data (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
devsjc authored Nov 27, 2023
1 parent 6a7c322 commit 21a1663
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/nwp_consumer/cmd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,14 @@ def main() -> None:
"""Entry point for the nwp-consumer CLI."""
# Parse command line arguments from docstring
arguments = docopt(__doc__, version=__version__)
erred = False

programStartTime = dt.datetime.now()
try:
run(arguments=arguments)
except Exception as e:
log.error("nwp-consumer error", error=str(e), exc_info=True)
log.error("encountered error running nwp-consumer", error=str(e), exc_info=True)
erred = True
finally:
leftoverTempPaths = list(internal.TMP_DIR.glob("*"))
for p in leftoverTempPaths:
Expand All @@ -191,6 +193,8 @@ def main() -> None:
elapsed_time=str(elapsedTime),
version=__version__
)
if erred:
exit(1)


if __name__ == "__main__":
Expand Down
6 changes: 6 additions & 0 deletions src/nwp_consumer/internal/inputs/ecmwf/mars.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ def listRawFilesForInitTime(self, *, it: dt.datetime) \
if it.hour not in [0, 12]:
return []

# MARS requests can only ask for data that is more than 24 hours old: see
# https://confluence.ecmwf.int/display/UDOC/MARS+access+restrictions
if it > dt.datetime.utcnow() - dt.timedelta(hours=24):
raise ValueError("ECMWF MARS requests can only ask for data that is more than 24 hours old")
return []

with tempfile.NamedTemporaryFile(suffix=".txt", mode="r+") as tf:

marsReq: str = f"""
Expand Down
6 changes: 1 addition & 5 deletions src/nwp_consumer/internal/inputs/icon/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ def listRawFilesForInitTime(self, *, it: dt.datetime) -> list[internal.FileInfoM
# ICON data is only available for today's date. If data hasn't been uploaded for that init
# time yet, then yesterday's data will still be present on the server.
if it.date() != dt.datetime.now(dt.timezone.utc).date():
log.warn(
event="ICON data is only available on today's date",
attempteddate=it.strftime("%Y-%m-%d"),
currentdate=dt.datetime.now(dt.timezone.utc).strftime("%Y-%m-%d"),
)
raise ValueError("ICON data is only available on today's date")
return []

# The ICON model only runs on the hours [00, 06, 12, 18]
Expand Down

0 comments on commit 21a1663

Please sign in to comment.