Coverage for src/hdmf/build/errors.py: 100%

27 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-10-04 02:57 +0000

1"""Module for build error definitions""" 

2from .builders import Builder 

3from ..container import AbstractContainer 

4from ..utils import docval, getargs 

5 

6 

7class BuildError(Exception): 

8 """Error raised when building a container into a builder.""" 

9 

10 @docval({'name': 'builder', 'type': Builder, 'doc': 'the builder that cannot be built'}, 

11 {'name': 'reason', 'type': str, 'doc': 'the reason for the error'}) 

12 def __init__(self, **kwargs): 

13 self.__builder = getargs('builder', kwargs) 

14 self.__reason = getargs('reason', kwargs) 

15 self.__message = "%s (%s): %s" % (self.__builder.name, self.__builder.path, self.__reason) 

16 super().__init__(self.__message) 

17 

18 

19class OrphanContainerBuildError(BuildError): 

20 

21 @docval({'name': 'builder', 'type': Builder, 'doc': 'the builder containing the broken link'}, 

22 {'name': 'container', 'type': AbstractContainer, 'doc': 'the container that has no parent'}) 

23 def __init__(self, **kwargs): 

24 builder = getargs('builder', kwargs) 

25 self.__container = getargs('container', kwargs) 

26 reason = ("Linked %s '%s' has no parent. Remove the link or ensure the linked container is added properly." 

27 % (self.__container.__class__.__name__, self.__container.name)) 

28 super().__init__(builder=builder, reason=reason) 

29 

30 

31class ReferenceTargetNotBuiltError(BuildError): 

32 

33 @docval({'name': 'builder', 'type': Builder, 'doc': 'the builder containing the reference that cannot be found'}, 

34 {'name': 'container', 'type': AbstractContainer, 'doc': 'the container that is not built yet'}) 

35 def __init__(self, **kwargs): 

36 builder = getargs('builder', kwargs) 

37 self.__container = getargs('container', kwargs) 

38 reason = ("Could not find already-built Builder for %s '%s' in BuildManager" 

39 % (self.__container.__class__.__name__, self.__container.name)) 

40 super().__init__(builder=builder, reason=reason) 

41 

42 

43class ContainerConfigurationError(Exception): 

44 """Error raised when the container class is improperly configured.""" 

45 pass 

46 

47 

48class ConstructError(Exception): 

49 """Error raised when constructing a container from a builder."""