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

Error handling #15

Closed
wants to merge 3 commits into from
Closed

Error handling #15

wants to merge 3 commits into from

Conversation

peverwhee
Copy link
Owner

@peverwhee peverwhee commented Mar 18, 2024

Summary

Update error handling to print out (most) parse/analyze errors after analyze happens.

Description

  1. Add error list and error printing method to VarDictionary for use by Suite, Group, and Scheme during analyze phase.
  2. Update the way parsing errors are handled and instead return them to the ccpp_capgen level so they can be combined with analyze errors in output.
  3. Add error list as optional argument to error checking functions so we optionally don't raise an exception and instead send those back to, ultimately, the ccpp_capgen level.

User interface changes?: No

Testing

  • Ideally will add a unit test to test all the expected behavior of these errors...

Sample Output

PARSE SCHEME ERRORS:
  Validity check errors:
    Invalid 'units' property value, 'flashes 5 min-1', at /glade/u/home/courtneyp/Projects/ccpp-framework/test/advection_test/cld_ice.meta:81
    Invalid 'flashes 5 min-1' is not a valid unit, 'flashes 5 min-1', at /glade/u/home/courtneyp/Projects/ccpp-framework/test/advection_test/cld_ice.meta:81
  3 errors found comparing
   /glade/u/home/courtneyp/Projects/ccpp-framework/test/advection_test/cld_ice.meta to
   /glade/u/home/courtneyp/Projects/ccpp-framework/test/advection_test/cld_ice.F90:
    Variable mismatch in cld_ice_init, variables missing from metadata header.
    Out of order argument, errmsg in cld_ice_init
    Out of order argument, errflg in cld_ice_init
ANALYZE ERRORS:
  1 error found when analyzing cld_ice:
    Input argument for cld_ice_init, water_temperature_at_freezingl, not found.
  2 errors found when analyzing cld_liq:
    Unsupported unit conversion, 'm' to 's' for 'time_step_for_physics'
    Input argument for cld_liq_run, minimum_temperature_for_cloud_liquids, not found.

@mwaxmonsky
Copy link
Collaborator

Okay, with a bit of digging around in the logger source, I think we might be able to use something like:

class Manager():
    def __init__(self):
        self.els = {}
    
    def getErrors(self, name):
        if name in self.els:
            return self.els[name]
        else:
            el = ErrorList()
            self.els[name] = el
            return el


class ErrorList():
    def __init__(self):
        self.errors = []

    def error(self, msg):
        self.errors.append(msg)

class Errors():
    def __init__(self):
        self.manager = Manager()

Errors.manager = Manager()


def getErrors(name):
    return Errors.manager.getErrors(name)

There's possibly some things in here we don't need and can be trimmed down but in a test environment, it would be used like:

(venv) bash-4.2$ python
Python 3.11.5 (main, Sep 11 2023, 13:54:46) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import Errors
>>> el = Errors.getErrors("myErrors")
>>> el.error("really bad")
>>> print(el.errors)
['really bad']
>>> el2 = Errors.getErrors("otherErrors")
>>> el2.error("no, it's REALLY bad")
>>> print(el2.errors)
["no, it's REALLY bad"]
>>> print(el.errors)
['really bad']

Does this seem like a reasonable implementation?

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