ErrorHandler

class ErrorHandler(check_for_warnings=True)[source]

Class to hold error context and having general error functions.

Methods

ErrorHandler.__init__([check_for_warnings])

ErrorHandler.add_context_and_filter(issues)

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

ErrorHandler.filter_issues_by_severity(...)

Gather all issues matching or below a given severity.

ErrorHandler.format_error(error_type, *args)

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

ErrorHandler.format_error_from_context(...)

Format an error based on the error type.

ErrorHandler.format_error_with_context(...)

ErrorHandler.pop_error_context()

Remove the last scope from the error context.

ErrorHandler.push_error_context(...)

Push a new error context to narrow down error scope.

ErrorHandler.reset_error_context()

Reset all error context information to defaults.

ErrorHandler.val_error_unknown(**kwargs)

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

Attributes

ErrorHandler.__init__(check_for_warnings=True)[source]
ErrorHandler.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.

static ErrorHandler.filter_issues_by_severity(issues_list, severity)[source]

Gather all issues matching or below a given severity.

Parameters:
  • issues_list (list) – 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

static ErrorHandler.format_error(error_type, *args, actual_error=None, **kwargs)[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

Notes

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

static ErrorHandler.format_error_from_context(error_type, error_context, *args, actual_error=None, **kwargs)[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

Notes

  • Generally the error_context is returned from _add_context_to_errors.

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

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

ErrorHandler.format_error_with_context(*args, **kwargs)[source]
ErrorHandler.pop_error_context()[source]

Remove the last scope from the error context.

Notes

Modifies the error context of this reporter.

ErrorHandler.push_error_context(context_type, context)[source]

Push a new error context to narrow down error scope.

Parameters:
  • context_type (ErrorContext) – 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.

ErrorHandler.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.

ErrorHandler.val_error_unknown(**kwargs)[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