Skip to content

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

Merged
merged 4 commits into from
Sep 24, 2019

Conversation

chriselion
Copy link
Contributor

@chriselion chriselion commented Sep 20, 2019

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:

  1. One part that loads the file and passes the file object to another function
  2. One part that does the actual loading from the file object
    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).

)
except UnicodeDecodeError:
raise UnityEnvironmentException(
f"There was an error decoding Config file from {trainer_config_path}. "
Copy link
Contributor Author

@chriselion chriselion Sep 20, 2019

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.

Copy link
Contributor

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):
Copy link
Contributor Author

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:
Copy link
Contributor Author

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 :/

Copy link
Contributor

@harperj harperj left a 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}. "
Copy link
Contributor

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

@chriselion chriselion merged commit efc9d84 into develop Sep 24, 2019
@chriselion chriselion deleted the develop-yaml-json-loading-errors branch September 24, 2019 22:45
@chriselion chriselion changed the title Develop yaml json loading errors Improve error messages for yaml and json loading errors Oct 1, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants