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

Add better load_schema_version error #591

Merged
merged 1 commit into from
Feb 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions hed/errors/error_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,16 +395,17 @@ def get_exception_issue_string(issues, title=None):
str: A str containing printable version of the issues or ''.

"""

issue_str = ''
if issues:
translated_messages = []
issue_list = []
for issue in issues:
if isinstance(issue, str):
translated_messages.append(f"ERROR: {issue}.")
else:
translated_messages.append(f"ERROR: {issue[1]}.\n Source Line: {issue[0]}")
issue_str += '\n' + '\n'.join(translated_messages)
this_str = f"{issue['message']}"
if 'code' in issue:
this_str = f"{issue['code']}:" + this_str
if 'line_number' in issue:
this_str = this_str + f"\n\tLine number {issue['line_number']}: {issue.get('line', '')} "
issue_list.append(this_str)
issue_str += '\n' + '\n'.join(issue_list)
if title:
issue_str = title + '\n' + issue_str
return issue_str
Expand Down
2 changes: 2 additions & 0 deletions hed/schema/hed_schema_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ def _load_schema_version(xml_version=None, xml_folder=None):
if e.error_type == HedExceptions.FILE_NOT_FOUND:
hed_cache.cache_xml_versions()
final_hed_xml_file = hed_cache.get_hed_version_path(xml_version, library_name, xml_folder)
if not final_hed_xml_file:
raise HedFileError(HedExceptions.FILE_NOT_FOUND, f"HED version '{xml_version}' not found in cache: {hed_cache.get_cache_directory()}", filename=xml_folder)
hed_schema = load_schema(final_hed_xml_file)
else:
raise e
Expand Down