-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Improve error messages for yaml and json loading errors #2601
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
Conversation
) | ||
except UnicodeDecodeError: | ||
raise UnityEnvironmentException( | ||
f"There was an error decoding Config file from {trainer_config_path}. " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made these exception messages a bit more generic since they're used for both Trainer and Sampler config loading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case I'd recommend renaming the argument to just config_path
@@ -117,3 +111,27 @@ def get_config(self, lesson=None): | |||
for key in parameters: | |||
config[key] = parameters[key][lesson] | |||
return config | |||
|
|||
@staticmethod | |||
def load_curriculum_file(location): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept these in the same file, but I can move them to trainer_util.py if that's cleaner. It's currently the only place we load json.
raise CurriculumLoadingError( | ||
"The file {0} could not be found.".format(location) | ||
) | ||
except UnicodeDecodeError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be handled in _load_curriculum instead, but I couldn't reproduce it to confirm :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, had a minor naming suggestion. I also couldn't manage to reproduce the UnicodeDecodeError ¯\(ツ)/¯
) | ||
except UnicodeDecodeError: | ||
raise UnityEnvironmentException( | ||
f"There was an error decoding Config file from {trainer_config_path}. " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case I'd recommend renaming the argument to just config_path
Since a common source of user problems and github issues is yaml/json configuration problems, I wanted to make the loading errors more explicit and point users to where they can validate their files.
I also split the loading into two parts to make testing and error checking a little clearer:
It's easier to test the second function by using an
io.StringIO
(otherwise you have to mock open() and it's ugly).I also split the CurriculumError into CurriculumLoadingError (for errors loading the file) and CurriculumConfigError (for semantic errors using the loaded file).
I noticed both json and yaml loading had some exception handling around UnicodeDecodeError but I'm not sure how to reproduce this in a test (but I assume it was there for a good reason).