Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/error typology #183

Merged
merged 3 commits into from
Jul 24, 2024
Merged

Feature/error typology #183

merged 3 commits into from
Jul 24, 2024

Conversation

EddyCMWF
Copy link
Contributor

Now that the broker can handle custom exceptions we should make use of them, this information will then be available in Splunk for categorising failed requests

@malmans2
Copy link
Member

LGTM. I tested this:

import cads_api_client

client = cads_api_client.ApiClient()
collection_id = "reanalysis-era5-land-monthly-means"
request = {
    "product_type": ["monthly_averaged_reanalysis"],
    "variable": ["u_component_of_wind", "v_component_of_wind", "2m_temperature"],
    "year": "2023",
    "month": "01",
    "format": "grib",
}
client.retrieve(collection_id, **request)

and I got this:

---------------------------------------------------------------------------
ProcessingFailedError                     Traceback (most recent call last)
Cell In[5], line 1
----> 1 client.retrieve(collection_id, **request)

File /src/cads-api-client/cads_api_client/api_client.py:68, in ApiClient.retrieve(self, collection_id, target, retry_options, **request)
     60 def retrieve(
     61     self,
     62     collection_id: str,
   (...)
     65     **request: Any,
     66 ) -> str:
     67     collection = self.collection(collection_id)
---> 68     return collection.retrieve(
     69         target,
     70         retry_options=retry_options,
     71         **request,
     72     )

File /src/cads-api-client/cads_api_client/catalogue.py:64, in Collection.retrieve(self, target, retry_options, **request)
     57 def retrieve(
     58     self,
     59     target: Optional[str] = None,
     60     retry_options: Dict[str, Any] = {},
     61     **request: Any,
     62 ) -> str:
     63     remote = self.submit(**request)
---> 64     return remote.download(target, retry_options=retry_options)

File /src/cads-api-client/cads_api_client/processing.py:289, in Remote.download(self, target, retry_options)
    286 def download(
    287     self, target: Optional[str] = None, retry_options: Dict[str, Any] = {}
    288 ) -> str:
--> 289     self.wait_on_result(retry_options=retry_options)
    290     return self._download_result(target, retry_options=retry_options)

File /src/cads-api-client/cads_api_client/processing.py:240, in Remote.wait_on_result(self, retry_options)
    238 elif status == "failed":
    239     results = multiurl.robust(self.make_results, **retry_options)(self.url)
--> 240     raise ProcessingFailedError(error_json_to_message(results.json))
    241 elif status in ("accepted", "running"):
    242     sleep *= 1.5

ProcessingFailedError: The job has failed.
MARS returned no data, please check your selection.Request submitted to the MARS server:
[{'dataset': ['reanalysis-monthly-means-of-daily-means'], 'param': ['u_component_of_wind', 'v_component_of_wind', '167'], 'class': ['l5'], 'expect': ['any'], 'number': ['all'], 'levtype': ['sfc'], 'date': ['2023-01-01']}]

The job failed with: MarsNoDataError

@EddyCMWF EddyCMWF requested review from malmans2 and removed request for francesconazzaro July 24, 2024 12:47
@EddyCMWF
Copy link
Contributor Author

LGTM. I tested this:

import cads_api_client

client = cads_api_client.ApiClient()
collection_id = "reanalysis-era5-land-monthly-means"
request = {
    "product_type": ["monthly_averaged_reanalysis"],
    "variable": ["u_component_of_wind", "v_component_of_wind", "2m_temperature"],
    "year": "2023",
    "month": "01",
    "format": "grib",
}
client.retrieve(collection_id, **request)

and I got this:

---------------------------------------------------------------------------
ProcessingFailedError                     Traceback (most recent call last)
Cell In[5], line 1
----> 1 client.retrieve(collection_id, **request)

File /src/cads-api-client/cads_api_client/api_client.py:68, in ApiClient.retrieve(self, collection_id, target, retry_options, **request)
     60 def retrieve(
     61     self,
     62     collection_id: str,
   (...)
     65     **request: Any,
     66 ) -> str:
     67     collection = self.collection(collection_id)
---> 68     return collection.retrieve(
     69         target,
     70         retry_options=retry_options,
     71         **request,
     72     )

File /src/cads-api-client/cads_api_client/catalogue.py:64, in Collection.retrieve(self, target, retry_options, **request)
     57 def retrieve(
     58     self,
     59     target: Optional[str] = None,
     60     retry_options: Dict[str, Any] = {},
     61     **request: Any,
     62 ) -> str:
     63     remote = self.submit(**request)
---> 64     return remote.download(target, retry_options=retry_options)

File /src/cads-api-client/cads_api_client/processing.py:289, in Remote.download(self, target, retry_options)
    286 def download(
    287     self, target: Optional[str] = None, retry_options: Dict[str, Any] = {}
    288 ) -> str:
--> 289     self.wait_on_result(retry_options=retry_options)
    290     return self._download_result(target, retry_options=retry_options)

File /src/cads-api-client/cads_api_client/processing.py:240, in Remote.wait_on_result(self, retry_options)
    238 elif status == "failed":
    239     results = multiurl.robust(self.make_results, **retry_options)(self.url)
--> 240     raise ProcessingFailedError(error_json_to_message(results.json))
    241 elif status in ("accepted", "running"):
    242     sleep *= 1.5

ProcessingFailedError: The job has failed.
MARS returned no data, please check your selection.Request submitted to the MARS server:
[{'dataset': ['reanalysis-monthly-means-of-daily-means'], 'param': ['u_component_of_wind', 'v_component_of_wind', '167'], 'class': ['l5'], 'expect': ['any'], 'number': ['all'], 'levtype': ['sfc'], 'date': ['2023-01-01']}]

The job failed with: MarsNoDataError

And this is the expected error, i.e. on cds-beta this currently returns RuntimeError but at the same point in the code

@EddyCMWF EddyCMWF merged commit a2740fc into main Jul 24, 2024
9 checks passed
@EddyCMWF EddyCMWF deleted the feature/error-typology branch July 24, 2024 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants