Skip to content

[FIX] Update error handling in adfactory#86

Merged
teald merged 4 commits intomainfrom
fix/error-management
Mar 4, 2025
Merged

[FIX] Update error handling in adfactory#86
teald merged 4 commits intomainfrom
fix/error-management

Conversation

@teald
Copy link
Member

@teald teald commented Mar 4, 2025

Summary

In DRAGONS, exceptions caught during certain critical AstroDataFactory methods, like ._open_file and .get_astro_data were discarded. This caused problems with testing, debugging, and maintenance of astrodata. It also makes development (with or of) astrodata more difficult when working on file handlers or AstroData objects.

The previous (quick) solution to this was to log the exceptions. However, DRAGONS expects that logs are clean in instances where there are no issues with creating an AstroData object from a file/from data. The log level for that message was also too high (error).

This PR decreases the logging level for these messages (debug), and intead catched errors. Caught exceptions are only reported if the data fails to match at all and there were exceptions raised while matching was occuring. This preserves the expected behavior while providing a more informative exception message.

Notes

This only works if no registered AstroData<Name> class object successfully matches, or none of the file openers in AstroDataFactory._file_openers successfully open the file. E.g., it still will not report exceptions if any objects/file openers are "successful", even if unintentional or unexpected.

To remedy that while preserving previous behavior, messages are still logged at the "debug" level to aid in debugging problems with AstroDataFactory.

teald added 3 commits March 4, 2025 14:00
In DRAGONS astrodata, exceptions are just passed. This makes certain
frequent debugging issues painful, because relevant exceptions are
obscured and therefore the source of a (real) problem is lost.

This update keeps the errors around, and reports them if no matching
astrodata object is found. This was originally logged, but that choice
doesn't coincide with DRAGON's logging principles (and it was also too
high of an error level, in any case).

This solution captures exceptions and reports them (as part of the error
message, with stack traces) if the matching process fails. If there are
no exceptions, or the process succeeds, behavior is still preserved as
it was.
Same as with get_astro_data, but for opening the file.
@teald teald added bug Something isn't working misc Miscellaneous (not covered by other tags) DRAGONS Related to DRAGONS development labels Mar 4, 2025
@teald teald marked this pull request as ready for review March 4, 2025 23:22
@teald teald merged commit 9e85df1 into main Mar 4, 2025
14 checks passed
@teald teald deleted the fix/error-management branch March 4, 2025 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working DRAGONS Related to DRAGONS development misc Miscellaneous (not covered by other tags)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant