Skip to content

Commit

Permalink
Replace HedFileError with ValueError to be consistent with NWB
Browse files Browse the repository at this point in the history
  • Loading branch information
VisLab committed Jul 8, 2024
1 parent 755c434 commit 43ee573
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
13 changes: 6 additions & 7 deletions src/pynwb/ndx_hed/hed_tags.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from collections.abc import Iterable

from hdmf.common import VectorData
from hdmf.utils import docval, getargs, get_docval, popargs
from hed.errors import HedFileError, get_printable_issue_string
from hed.schema import HedSchema, HedSchemaGroup, load_schema_version, from_string
from hed.errors import get_printable_issue_string
from hed.schema import load_schema_version
from hed.models import HedString
from pynwb import register_class
from pynwb.file import LabMetaData, NWBFile


@register_class('HedTags', 'ndx-hed')
Expand Down Expand Up @@ -42,7 +41,8 @@ def _init_internal(self):
if these_issues:
issues.append(f"line {str(index)}: {get_printable_issue_string(these_issues)}")
if issues:
raise HedFileError("InvalidHEDData", "\n".join(issues), "")
issue_str = "\n".join(issues)
raise ValueError(f"InvalidHEDData {issue_str}")

@docval({'name': 'val', 'type': str,
'doc': 'the value to add to this column. Should be a valid HED string -- just forces string.'})
Expand All @@ -52,8 +52,7 @@ def add_row(self, **kwargs):
hed_obj = HedString(val, self._hed_schema)
these_issues = hed_obj.validate()
if these_issues:
raise HedFileError("InvalidHEDValue",
f"{str(val)} issues: {get_printable_issue_string(these_issues)}", "")
raise ValueError(f"InvalidHEDValue [{str(val)}] issues: {get_printable_issue_string(these_issues)}")
super().append(val)

def get_hed_version(self):
Expand Down
8 changes: 4 additions & 4 deletions src/pynwb/tests/test_hed_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def test_bad_schema_version(self):

def test_constructor_bad_data(self):
"""Test setting HED values using the constructor."""
with self.assertRaises(HedFileError) as ex:
with self.assertRaises(ValueError) as ex:
HedTags(hed_version='8.2.0', data=["Blech, Red"])
self.assertEqual("InvalidHEDData", ex.args(0))
self.assertStartsWith("InvalidHEDData", ex)

def test_add_row(self):
"""Testing adding a row to the HedTags. """
Expand All @@ -53,9 +53,9 @@ def test_add_row(self):

def test_add_bad_row(self):
tags = HedTags(hed_version='8.2.0', data=["Correct-action", "Incorrect-action"])
with self.assertRaises(HedFileError) as ex:
with self.assertRaises(ValueError) as ex:
tags.add_row("Blech, (Red, Blue)")
self.assertIsInstance(ex, HedFileError)
self.assertIsInstance(ex, ValueError)
self.assertEqual(ex.args(0), "InvalidHEDData")

def test_get(self):
Expand Down

0 comments on commit 43ee573

Please sign in to comment.