Skip to content
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
3 changes: 2 additions & 1 deletion hed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
from hed.models.spreadsheet_input import SpreadsheetInput
from hed.models.tabular_input import TabularInput
from hed.models.sidecar import Sidecar
from hed.models.definition_dict import DefinitionDict


from hed.schema.hed_schema import HedSchema
from hed.schema.hed_schema_group import HedSchemaGroup
from hed.schema.hed_schema_io import get_schema, get_schema_versions, load_schema, load_schema_version

from hed.validator.hed_validator import HedValidator

# from hed import errors, models, schema, tools, validator

Expand Down
142 changes: 74 additions & 68 deletions hed/errors/error_messages.py

Large diffs are not rendered by default.

49 changes: 24 additions & 25 deletions hed/errors/error_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def wrapper(*args, severity=default_severity, **kwargs):
Returns:
list: A list of dict with the errors.=
"""
base_message, error_vars = func(*args, **kwargs)
error_object = ErrorHandler._create_error_object(actual_code, base_message, severity, **error_vars)
base_message = func(*args, **kwargs)
error_object = ErrorHandler._create_error_object(actual_code, base_message, severity)
return error_object

_register_error_function(error_type, wrapper_func=wrapper)
Expand Down Expand Up @@ -97,8 +97,8 @@ def wrapper(tag, index_in_tag, index_in_tag_end, *args, severity=default_severit
except AttributeError:
org_tag_text = str(tag)

base_message, error_vars = func(org_tag_text, problem_sub_tag, *args, **kwargs)
error_object = ErrorHandler._create_error_object(actual_code, base_message, severity, **error_vars,
base_message = func(org_tag_text, problem_sub_tag, *args, **kwargs)
error_object = ErrorHandler._create_error_object(actual_code, base_message, severity,
index_in_tag=index_in_tag,
index_in_tag_end=index_in_tag_end, source_tag=tag)

Expand Down Expand Up @@ -129,8 +129,8 @@ def wrapper(tag, *args, severity=default_severity, **kwargs):
org_tag_text = tag.get_original_hed_string()
else:
org_tag_text = str(tag)
base_message, error_vars = func(org_tag_text, *args, **kwargs)
error_object = ErrorHandler._create_error_object(actual_code, base_message, severity, **error_vars,
base_message = func(org_tag_text, *args, **kwargs)
error_object = ErrorHandler._create_error_object(actual_code, base_message, severity,
source_tag=tag)

return error_object
Expand All @@ -148,9 +148,10 @@ def wrapper(tag, *args, severity=default_severity, **kwargs):


class ErrorHandler:
def __init__(self):
def __init__(self, check_for_warnings=True):
# The current (ordered) dictionary of contexts.
self.error_context = []
self._check_for_warnings = check_for_warnings

def push_error_context(self, context_type, context, increment_depth_after=True):
""" Push a new error context to narrow down error scope.
Expand Down Expand Up @@ -191,8 +192,12 @@ def get_error_context_copy(self):
def format_error_with_context(self, *args, **kwargs):
error_object = ErrorHandler.format_error(*args, **kwargs)
if self is not None:
self._add_context_to_errors(error_object[0], self.error_context)
self._update_error_with_char_pos(error_object[0])
actual_error = error_object[0]
# # Filter out warning errors
if not self._check_for_warnings and actual_error['severity'] >= ErrorSeverity.WARNING:
return []
self._add_context_to_errors(actual_error, self.error_context)
self._update_error_with_char_pos(actual_error)

return error_object

Expand Down Expand Up @@ -225,26 +230,19 @@ def format_error(error_type, *args, actual_error=None, **kwargs):

return [error_object]

def add_context_to_issues(self, issues):
def add_context_and_filter(self, issues):
""" Filter out warnings if requested, while adding context to issues.

issues(list):
list: A list containing a single dictionary representing a single error.
"""
if not self._check_for_warnings:
issues[:] = self.filter_issues_by_severity(issues, ErrorSeverity.ERROR)

for error_object in issues:
self._add_context_to_errors(error_object, self.error_context)
self._update_error_with_char_pos(error_object)

def format_error_list(self, issue_params):
""" Convert an issue params list to an issues list. This means adding the error context primarily.

Parameters:
issue_params (list): A list of dict containing the unformatted issues list.

Returns:
list: A list of dict containing unformatted errors.

"""
formatted_issues = []
for issue in issue_params:
formatted_issues += self.format_error(**issue)
return formatted_issues

@staticmethod
def format_error_from_context(error_type, error_context, *args, actual_error=None, **kwargs):
""" Format an error based on the error type.
Expand All @@ -262,6 +260,7 @@ def format_error_from_context(error_type, error_context, *args, actual_error=Non
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.

"""
error_func = error_functions.get(error_type)
Expand Down
5 changes: 4 additions & 1 deletion hed/errors/error_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ValidationErrors:
HED_UNITS_DEFAULT_USED = 'HED_UNITS_DEFAULT_USED'
HED_VALUE_INVALID = 'HED_VALUE_INVALID'
HED_LIBRARY_UNMATCHED = "HED_LIBRARY_UNMATCHED"
TAG_PREFIX_INVALID = "TAG_PREFIX_INVALID"
# HED_VERSION_WARNING

HED_MISSING_REQUIRED_COLUMN = "HED_MISSING_REQUIRED_COLUMN"
Expand Down Expand Up @@ -75,12 +76,14 @@ class ValidationErrors:

class SidecarErrors:
# These are for json sidecar validation errors(sidecars can also produce most normal validation errors)
SIDECAR_INVALID = "SIDECAR_INVALID" # this is the generic error reported for several later ones
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'

class SchemaErrors:
HED_SCHEMA_DUPLICATE_NODE = 'HED_SCHEMA_DUPLICATE_NODE'
Expand Down
2 changes: 2 additions & 0 deletions hed/errors/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class HedExceptions:
CANNOT_PARSE_JSON = 'cannotParseJson'
INVALID_EXTENSION = 'invalidExtension'

INVALID_DATAFRAME = 'INVALID_DATAFRAME'

# These are actual schema issues, not that the file cannot be found or parsed
SCHEMA_HEADER_MISSING = 'HED_SCHEMA_HEADER_INVALID'
HED_SCHEMA_HEADER_INVALID = 'HED_SCHEMA_HEADER_INVALID'
Expand Down
3 changes: 0 additions & 3 deletions hed/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
from .column_metadata import ColumnMetadata, ColumnType
from .definition_dict import DefinitionDict
from .definition_entry import DefinitionEntry
from .def_mapper import DefMapper
from .expression_parser import QueryParser
from .hed_group import HedGroup
from .spreadsheet_input import SpreadsheetInput
from .hed_ops import HedOps
from .hed_string import HedString
from .hed_string_group import HedStringGroup
from .hed_tag import HedTag
from .onset_mapper import OnsetMapper
from .sidecar import Sidecar
from .tabular_input import TabularInput
from .timeseries_input import TimeseriesInput
Loading