diff --git a/src/nwp_consumer/cmd/main.py b/src/nwp_consumer/cmd/main.py index bad76b7e..37e86848 100644 --- a/src/nwp_consumer/cmd/main.py +++ b/src/nwp_consumer/cmd/main.py @@ -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: @@ -191,6 +193,8 @@ def main() -> None: elapsed_time=str(elapsedTime), version=__version__ ) + if erred: + exit(1) if __name__ == "__main__": diff --git a/src/nwp_consumer/internal/inputs/ecmwf/mars.py b/src/nwp_consumer/internal/inputs/ecmwf/mars.py index 03ca4716..63297f1e 100644 --- a/src/nwp_consumer/internal/inputs/ecmwf/mars.py +++ b/src/nwp_consumer/internal/inputs/ecmwf/mars.py @@ -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""" diff --git a/src/nwp_consumer/internal/inputs/icon/client.py b/src/nwp_consumer/internal/inputs/icon/client.py index aa3d3fce..174192ba 100644 --- a/src/nwp_consumer/internal/inputs/icon/client.py +++ b/src/nwp_consumer/internal/inputs/icon/client.py @@ -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]