Errors

Error handling and reporting classes for HED validation and processing.

Error Types and Constants

HedExceptions

class hed.errors.exceptions.HedExceptions[source]

Bases: object

HED exception codes.

GENERIC_ERROR = 'GENERIC_ERROR'
URL_ERROR = 'URL_ERROR'
FILE_NOT_FOUND = 'fileNotFound'
BAD_PARAMETERS = 'badParameters'
CANNOT_PARSE_XML = 'cannotParseXML'
CANNOT_PARSE_JSON = 'cannotParseJson'
INVALID_EXTENSION = 'invalidExtension'
INVALID_HED_FORMAT = 'INVALID_HED_FORMAT'
INVALID_DATAFRAME = 'INVALID_DATAFRAME'
INVALID_FILE_FORMAT = 'INVALID_FILE_FORMAT'
SCHEMA_HEADER_MISSING = 'SCHEMA_HEADER_INVALID'
SCHEMA_HEADER_INVALID = 'SCHEMA_HEADER_INVALID'
SCHEMA_UNKNOWN_HEADER_ATTRIBUTE = 'SCHEMA_HEADER_INVALID'
SCHEMA_LIBRARY_INVALID = 'SCHEMA_LIBRARY_INVALID'
BAD_HED_LIBRARY_NAME = 'SCHEMA_LIBRARY_INVALID'
BAD_WITH_STANDARD = 'SCHEMA_LIBRARY_INVALID'
BAD_WITH_STANDARD_MULTIPLE_VALUES = 'SCHEMA_LOAD_FAILED'
ROOTED_TAG_INVALID = 'SCHEMA_LIBRARY_INVALID'
ROOTED_TAG_HAS_PARENT = 'SCHEMA_LIBRARY_INVALID'
ROOTED_TAG_DOES_NOT_EXIST = 'SCHEMA_LIBRARY_INVALID'
IN_LIBRARY_IN_UNMERGED = 'SCHEMA_LIBRARY_INVALID'
INVALID_LIBRARY_PREFIX = 'SCHEMA_LIBRARY_INVALID'
SCHEMA_VERSION_INVALID = 'SCHEMA_VERSION_INVALID'
SCHEMA_SECTION_MISSING = 'SCHEMA_SECTION_MISSING'
SCHEMA_INVALID = 'SCHEMA_INVALID'
WIKI_SEPARATOR_INVALID = 'invalidSectionSeparator'
WIKI_DELIMITERS_INVALID = 'WIKI_DELIMITERS_INVALID'
WIKI_LINE_START_INVALID = 'WIKI_LINE_START_INVALID'
WIKI_LINE_INVALID = 'WIKI_LINE_INVALID'
HED_SCHEMA_NODE_NAME_INVALID = 'HED_SCHEMA_NODE_NAME_INVALID'
SCHEMA_DUPLICATE_PREFIX = 'SCHEMA_LOAD_FAILED'
SCHEMA_DUPLICATE_LIBRARY = 'SCHEMA_LIBRARY_INVALID'
BAD_COLUMN_NAMES = 'BAD_COLUMN_NAMES'
SCHEMA_DUPLICATE_NAMES = 'SCHEMA_DUPLICATE_NAMES'
CANNOT_PARSE_RDF = 'CANNOT_PARSE_RDF'
SCHEMA_LOAD_FAILED = 'SCHEMA_LOAD_FAILED'
SCHEMA_TAG_TSV_BAD_PARENT = 'SCHEMA_TAG_TSV_BAD_PARENT'

HedFileError

class hed.errors.exceptions.HedFileError(code, message, filename, issues=None)[source]

Bases: Exception

Exception raised when a file cannot be parsed due to being malformed, file IO, etc.

__init__(code, message, filename, issues=None)[source]

Error Reporting

ErrorHandler

class hed.errors.error_reporter.ErrorHandler(check_for_warnings=True)[source]

Bases: object

Class to hold error context and having general error functions.

__init__(check_for_warnings=True)[source]
push_error_context(context_type, context)[source]

Push a new error context to narrow down error scope.

Parameters:
  • context_type (str) – A value from ErrorContext representing the type of scope.

  • context (str, int, or HedString) – The main value for the context_type.

Notes

The context depends on the context_type. For ErrorContext.FILE_NAME this would be the actual filename.

pop_error_context()[source]

Remove the last scope from the error context.

Notes

Modifies the error context of this reporter.

reset_error_context()[source]

Reset all error context information to defaults.

Notes

This function is mainly for testing and should not be needed with proper usage.

add_context_and_filter(issues)[source]

Filter out warnings if requested, while adding context to issues.

issues(list):

list: A list containing a single dictionary representing a single error.

format_error_with_context(*args, **kwargs)[source]
static filter_issues_by_severity(issues_list: list[dict], severity: int) list[dict][source]

Gather all issues matching or below a given severity.

Parameters:
  • issues_list (list[dict]) – A list of dictionaries containing the full issue list.

  • severity (int) – The level of issues to keep.

Returns:

A list of dictionaries containing the issue list after filtering by severity.

Return type:

list[dict]

static format_error(error_type: str, *args, actual_error=None, **kwargs) list[dict][source]

Format an error based on the parameters, which vary based on what type of error this is.

Parameters:
  • error_type (str) – The type of error for this. Registered with @hed_error or @hed_tag_error.

  • args (args) – Any remaining non-keyword args after those required by the error type.

  • actual_error (str or None) – Code to actually add to report out.

  • kwargs (kwargs) – The other keyword args to pass down to the error handling func.

Returns:

A list containing a single dictionary representing a single error.

Return type:

list[dict]

Notes

The actual error is useful for errors that are shared like invalid character.

static format_error_from_context(error_type: str, error_context: list, *args, actual_error: str | None, **kwargs) list[dict][source]

Format an error based on the error type.

Parameters:
  • error_type (str) – The type of error. Registered with @hed_error or @hed_tag_error.

  • error_context (list) – Contains the error context to use for this error.

  • args (args) – Any remaining non-keyword args.

  • actual_error (str or None) – Error code to actually add to report out.

  • kwargs (kwargs) – Keyword parameters to pass down to the error handling func.

Returns:

A list containing a single dictionary.

Return type:

list[dict]

Notes

  • Generally the error_context is returned from _add_context_to_error.

  • The actual_error is useful for errors that are shared like invalid character.

  • This can’t filter out warnings like the other ones.

val_error_unknown(**kwargs) str[source]

Default error handler if no error of this type was registered.

Parameters:
  • args (args) – List of non-keyword parameters (varies).

  • kwargs (kwargs) – Keyword parameters (varies)

Returns:

The error message.

Return type:

str

static filter_issues_by_count(issues, count, by_file=False) tuple[list[dict], dict[str, int]][source]

Filter the issues list to only include the first count issues of each code.

Parameters:

issues (list): A list of dictionaries containing the full issue list. count (int): The number of issues to keep for each code. by_file (bool): If True, group by file name.

Returns:

A tuple containing:
  • A list of dictionaries representing the filtered issue list.

  • A dictionary with the codes as keys and the number of occurrences as values.

Return type:

tuple[list[dict], dict[str, int]]

static aggregate_code_counts(file_code_dict) dict[source]

Aggregate the counts of codes across multiple files.

Parameters:

file_code_dict (dict) – A dictionary where keys are filenames and values are dictionaries of code counts.

Returns:

A dictionary with the aggregated counts of codes across all files.

Return type:

dict

Error Functions

hed.errors.error_reporter.get_printable_issue_string(issues, title=None, severity=None, skip_filename=True, add_link=False, show_details=False) str[source]

Return a string with issues list flatted into single string, one per line.

Parameters:
  • issues (list) – Issues to print.

  • title (str) – Optional title that will always show up first if present(even if there are no validation issues).

  • severity (int) – Return only warnings >= severity.

  • skip_filename (bool) – If True, don’t add the filename context to the printable string.

  • add_link (bool) – Add a link at the end of message to the appropriate error if True

  • show_details (bool) – If True, show details about the issues.

Returns:

A string containing printable version of the issues or ‘’.

Return type:

str

hed.errors.error_reporter.sort_issues(issues, reverse=False) list[dict][source]

Sort a list of issues by the error context values.

Parameters:
  • issues (list) – A list of dictionaries representing the issues to be sorted.

  • reverse (bool, optional) – If True, sorts the list in descending order. Default is False.

Returns:

The sorted list of issues.

Return type:

list[dict]

hed.errors.error_reporter.replace_tag_references(list_or_dict)[source]

Utility function to remove any references to tags, strings, etc. from any type of nested list or dict.

Use this if you want to save out issues to a file.

If you’d prefer a copy returned, use replace_tag_references(list_or_dict.copy()).

Parameters:

list_or_dict (list or dict) – An arbitrarily nested list/dict structure

Error Types

ValidationErrors

class hed.errors.error_types.ValidationErrors[source]

Bases: object

CHARACTER_INVALID = 'CHARACTER_INVALID'
COMMA_MISSING = 'COMMA_MISSING'
DEF_EXPAND_INVALID = 'DEF_EXPAND_INVALID'
DEF_INVALID = 'DEF_INVALID'
DEFINITION_INVALID = 'DEFINITION_INVALID'
ELEMENT_DEPRECATED = 'ELEMENT_DEPRECATED'
TEMPORAL_TAG_ERROR = 'TEMPORAL_TAG_ERROR'
PARENTHESES_MISMATCH = 'PARENTHESES_MISMATCH'
PLACEHOLDER_INVALID = 'PLACEHOLDER_INVALID'
REQUIRED_TAG_MISSING = 'REQUIRED_TAG_MISSING'
SIDECAR_INVALID = 'SIDECAR_INVALID'
SIDECAR_KEY_MISSING = 'SIDECAR_KEY_MISSING'
HED_COLUMN_MISSING = 'HED_COLUMN_MISSING'
STYLE_WARNING = 'STYLE_WARNING'
TAG_EMPTY = 'TAG_EMPTY'
TAG_EXPRESSION_REPEATED = 'TAG_EXPRESSION_REPEATED'
TAG_EXTENDED = 'TAG_EXTENDED'
TAG_EXTENSION_INVALID = 'TAG_EXTENSION_INVALID'
TAG_GROUP_ERROR = 'TAG_GROUP_ERROR'
TAG_INVALID = 'TAG_INVALID'
TAG_NOT_UNIQUE = 'TAG_NOT_UNIQUE'
TAG_NAMESPACE_PREFIX_INVALID = 'TAG_NAMESPACE_PREFIX_INVALID'
TAG_REQUIRES_CHILD = 'TAG_REQUIRES_CHILD'
TILDES_UNSUPPORTED = 'TILDES_UNSUPPORTED'
UNITS_INVALID = 'UNITS_INVALID'
VERSION_DEPRECATED = 'VERSION_DEPRECATED'
VALUE_INVALID = 'VALUE_INVALID'
HED_DEF_UNMATCHED = 'HED_DEF_UNMATCHED'
HED_DEF_VALUE_MISSING = 'HED_DEF_VALUE_MISSING'
HED_DEF_VALUE_EXTRA = 'HED_DEF_VALUE_EXTRA'
HED_DEF_EXPAND_INVALID = 'HED_DEF_EXPAND_INVALID'
HED_DEF_EXPAND_UNMATCHED = 'HED_DEF_EXPAND_UNMATCHED'
HED_DEF_EXPAND_VALUE_MISSING = 'HED_DEF_EXPAND_VALUE_MISSING'
HED_DEF_EXPAND_VALUE_EXTRA = 'HED_DEF_EXPAND_VALUE_EXTRA'
HED_RESERVED_TAG_REPEATED = 'HED_RESERVED_TAG_REPEATED'
HED_RESERVED_TAG_GROUP_ERROR = 'HED_RESERVED_TAG_GROUP_ERROR'
HED_TAG_REPEATED = 'HED_TAG_REPEATED'
HED_TAG_REPEATED_GROUP = 'HED_TAG_REPEATED_GROUP'
INVALID_PARENT_NODE = 'invalidParent'
NO_VALID_TAG_FOUND = 'invalidTag'
NODE_NAME_EMPTY = 'NODE_NAME_EMPTY'
HED_LIBRARY_UNMATCHED = 'HED_LIBRARY_UNMATCHED'
HED_TOP_LEVEL_TAG = 'HED_TOP_LEVEL_TAG'
HED_MULTIPLE_TOP_TAGS = 'HED_MULTIPLE_TOP_TAGS'
HED_TAG_GROUP_TAG = 'HED_TAG_GROUP_TAG'
HED_TAGS_NOT_ALLOWED = 'HED_TAGS_NOT_ALLOWED'
HED_GROUP_EMPTY = 'HED_GROUP_EMPTY'
HED_MISSING_REQUIRED_COLUMN = 'HED_MISSING_REQUIRED_COLUMN'
HED_UNKNOWN_COLUMN = 'HED_UNKNOWN_COLUMN'
SIDECAR_AND_OTHER_COLUMNS = 'SIDECAR_AND_OTHER_COLUMNS'
DUPLICATE_COLUMN_IN_LIST = 'DUPLICATE_COLUMN_IN_LIST'
DUPLICATE_COLUMN_BETWEEN_SOURCES = 'DUPLICATE_COLUMN_BETWEEN_SOURCES'
HED_BLANK_COLUMN = 'HED_BLANK_COLUMN'
INVALID_VALUE_CLASS_CHARACTER = 'INVALID_VALUE_CLASS_CHARACTER'
INVALID_VALUE_CLASS_VALUE = 'INVALID_VALUE_CLASS_VALUE'
INVALID_TAG_CHARACTER = 'invalidTagCharacter'
HED_PLACEHOLDER_OUT_OF_CONTEXT = 'HED_PLACEHOLDER_OUT_OF_CONTEXT'
CURLY_BRACE_UNSUPPORTED_HERE = 'CURLY_BRACE_UNSUPPORTED_HERE'
ONSETS_UNORDERED = 'ONSETS_UNORDERED'
TSV_COLUMN_MISSING = 'TSV_COLUMN_MISSING'

SchemaErrors

class hed.errors.error_types.SchemaErrors[source]

Bases: object

SCHEMA_DUPLICATE_NODE = 'SCHEMA_DUPLICATE_NODE'
SCHEMA_DUPLICATE_FROM_LIBRARY = 'SCHEMA_LIBRARY_INVALID'
SCHEMA_INVALID_SIBLING = 'SCHEMA_INVALID_SIBLING'
SCHEMA_INVALID_CHILD = 'SCHEMA_INVALID_CHILD'

SidecarErrors

class hed.errors.error_types.SidecarErrors[source]

Bases: object

BLANK_HED_STRING = 'blankValueString'
WRONG_HED_DATA_TYPE = 'wrongHedDataType'
INVALID_POUND_SIGNS_VALUE = 'invalidNumberPoundSigns'
INVALID_POUND_SIGNS_CATEGORY = 'tooManyPoundSigns'
UNKNOWN_COLUMN_TYPE = 'sidecarUnknownColumn'
SIDECAR_HED_USED = 'SIDECAR_HED_USED'
SIDECAR_NA_USED = 'SIDECAR_NA_USED'
SIDECAR_BRACES_INVALID = 'SIDECAR_BRACES_INVALID'

ErrorContext

class hed.errors.error_types.ErrorContext[source]

Bases: object

Context this error took place in, each error potentially having multiple contexts.

CUSTOM_TITLE = 'ec_title'
FILE_NAME = 'ec_filename'
SIDECAR_COLUMN_NAME = 'ec_sidecarColumnName'
SIDECAR_KEY_NAME = 'ec_sidecarKeyName'
ROW = 'ec_row'
COLUMN = 'ec_column'
LINE = 'ec_line'
HED_STRING = 'ec_HedString'
SCHEMA_SECTION = 'ec_section'
SCHEMA_TAG = 'ec_schema_tag'
SCHEMA_ATTRIBUTE = 'ec_attribute'

ErrorSeverity

class hed.errors.error_types.ErrorSeverity[source]

Bases: object

Severity codes for errors

ERROR = 1
WARNING = 10