Skip to content

Gracefully handle the case of missing facets required by esmvalcore.io.local.LocalDataSource#3021

Open
bouweandela wants to merge 7 commits intomainfrom
relax-local-data-source-facet-requirement
Open

Gracefully handle the case of missing facets required by esmvalcore.io.local.LocalDataSource#3021
bouweandela wants to merge 7 commits intomainfrom
relax-local-data-source-facet-requirement

Conversation

@bouweandela
Copy link
Member

@bouweandela bouweandela commented Mar 19, 2026

Description

Do not raise an exception if a facet required by esmvalcore.io.local.LocalDataSource is missing, but log the problem and continue. Maybe the data can be found using some other data source and if not, the user will see the log message.

Closes #2995

Link to documentation:


Before you get started

Checklist

It is the responsibility of the author to make sure the pull request is ready to review. The icons indicate whether the item will be subject to the 🛠 Technical or 🧪 Scientific review.


To help with the number pull requests:

@bouweandela bouweandela added the enhancement New feature or request label Mar 19, 2026
@bouweandela bouweandela changed the title Gracefully handle the case of missing facets required by esmvalcore.io.local.LocalDataSource Gracefully handle the case of missing facets required by esmvalcore.io.local.LocalDataSource Mar 19, 2026
@codecov
Copy link

codecov bot commented Mar 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.70%. Comparing base (69f2019) to head (dfc2076).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3021   +/-   ##
=======================================
  Coverage   95.70%   95.70%           
=======================================
  Files         267      267           
  Lines       15768    15792   +24     
=======================================
+ Hits        15090    15114   +24     
  Misses        678      678           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bouweandela bouweandela marked this pull request as ready for review March 19, 2026 08:29
@bouweandela bouweandela requested a review from schlunma March 19, 2026 08:29
Copy link
Contributor

@schlunma schlunma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks Bouwe! Works exactly as expected.

I just have some minor comments on the code.

Comment on lines +423 to +424
class MissingFacetError(KeyError):
"""Error raised when a facet required for filling the template is missing."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason why you're not putting this into esmvalcore.exceptions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is intended for internal use in this module. I made it private in c8d9225.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any public function that raises this exception? I find it always nice when packages make exceptions public in order to catch them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, it's also used by the (deprecated) functionality to get the preprocessor output file name in esmvalcore.local. Let me make sure it's caught there too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solved in c64c373. There are no more functions left that do not catch the exception if it is raised.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed now..

Comment on lines -332 to -339
glob_patterns.extend(
data_source._get_glob_patterns(**self.extra_facets), # noqa: SLF001
)
possible_grid_paths = [d.parent / grid_name for d in glob_patterns]
for grid_path in possible_grid_paths:
if grid_path.is_file():
logger.debug("Using ICON grid file '%s'", grid_path)
return self._load_cubes(grid_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, this does not work (ICON grid files are not found anymore). Code looks ok, don't really know why.

Maybe just try/except the exception similar to the other changes? It's probably not worth it to investigate this in detail..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then the issue would not be solved for the ICON project. Do you have a recipe I can run on Levante to test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

All facets for all configured data sources of a project are always required

2 participants