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

Nondiscriminatory error handling in raiseorpush #6

Open
tomjanus opened this issue Sep 2, 2023 · 0 comments
Open

Nondiscriminatory error handling in raiseorpush #6

tomjanus opened this issue Sep 2, 2023 · 0 comments

Comments

@tomjanus
Copy link

tomjanus commented Sep 2, 2023

Nondiscriminatory error handling in the raiseorpush context manager masks errors not related to parsing and validation.

For example, in parsers/pywrjsonparser.py changing lines 141-143 from the original code:

with component_exc_capture("metadata") as cc:
            self.metadata = PywrMetadata(self.src["metadata"])
            cc.capture_warnings(self.metadata)

to

with component_exc_capture("metadata") as cc:
            self.metadata = PywrMetadata(self.src["metadata"])
            cc.capture_warnings("some other variable")

will not generate an exception.

To fix, update the __exit__ dunder method in lines 34-42 in utils .py to:

    def __exit__(self, exc_type, exc_obj, exc_tb):
        if isinstance(exc_obj, WNTREPANETTypeValidationErrorBundle):
            for error in exc_obj.errors:
                #  Raise on warning implies raise on error
                if self.raise_warning or self.raise_error:
                    raise error from None
                self.dest.errors[self.component].append(error)
        elif exc_obj is not None:
            raise(exc_obj) from exc_obj
        return not self.raise_warning
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

No branches or pull requests

1 participant