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

Amend validation error raised #506

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open

Conversation

drc38
Copy link
Contributor

@drc38 drc38 commented Nov 3, 2023

With the incorporation of #494 an OSError should only be raised on edge cases eg if the json schema file is corrupt. NotImplementedError and NotSupportedError errors will be raised prior to the json validation occurring, taking care of when the schema doesn't exist.

@drc38 drc38 requested a review from OrangeTux as a code owner November 3, 2023 10:24
ocpp/messages.py Outdated
Comment on lines 223 to 225
except json.JSONDecodeError:
raise ValidationError(
f"Error in decoding JSON validation schema for action: {message.action}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Only a json.JSONDecodeError should be mapped to a ValidationError. An OSError means that no schema with a given name was found. That means user is using a action that doesn't exists. Therefore, a NotSupportedError is applicable. See my comment here: #494 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With #494 a FileNotFoundError should not be raised by the OSError exception, as before it gets to this part of the code a NotSupportedError will be raised by_raise_key_error. So an OSError should only be raised for one of these other reasons https://docs.python.org/3/library/exceptions.html#os-exceptions

@Jared-Newell-Mobility
Copy link
Contributor

If possible could you please add to this PR an entry in ChangeLog.md?

@drc38 drc38 requested review from mdwcrft and proelke as code owners October 16, 2024 03:45
@drc38 drc38 mentioned this pull request Dec 9, 2024
@jainmohit2001
Copy link
Collaborator

@drc38 Should we take this up?
Can you please share e brief about the changes done in this PR. Sorry, I am out of loop for this one.
Also, please remove the changes in CHANGELOG.md. I believe we will handle that while creating a new release.

@drc38
Copy link
Contributor Author

drc38 commented Dec 19, 2024

Hi @jainmohit2001 as per discussion above these two errors should only be raised on edge cases if the validation has failed. Prior to this part of the code being executed a NotSupportedError is raised if the ocpp spec does not include the message sent or a NotImplementedError if server/client using this library has not coded to process message will be raised. Hence if neither is raised and a json.JSONDecodeError occurs during parsing the json schema file it should be raised as a ValidationError (could occur if the files were manually altered). If an OSError occurs it should also be raised as a ValidationError because it indicates for some reason the filesystem and .json files cannot be read (seems very unlikely to occur eg disk/file corruption).

My view is it should be merged.

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

Successfully merging this pull request may close these issues.

4 participants