summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2017-08-22 09:00:53 +0200
committerAnthon van der Neut <anthon@mnt.org>2017-08-22 09:00:53 +0200
commit10d88a29cf50dc4679a3b079353cd593113d3e41 (patch)
tree2ff3907487554c0172c360fc6a4a496ce3562493
parent6e1fdb5e141ee93a15d59ba0d80415ad10a8bb12 (diff)
downloadruamel.yaml-10d88a29cf50dc4679a3b079353cd593113d3e41.tar.gz
fix issue #148: unclear error message when failing to parse timestamp
*When this change resolves your problem, please **Close** this issue*. (You can do so using the WorkFlow pull-down (close to the top right of this page)
-rw-r--r--constructor.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/constructor.py b/constructor.py
index dcf8e02..c77d11c 100644
--- a/constructor.py
+++ b/constructor.py
@@ -486,7 +486,15 @@ class SafeConstructor(BaseConstructor):
def construct_yaml_timestamp(self, node, values=None):
# type: (Any, Any) -> Any
if values is None:
- match = self.timestamp_regexp.match(node.value)
+ try:
+ match = self.timestamp_regexp.match(node.value)
+ except TypeError:
+ match = None
+ if match is None:
+ raise ConstructorError(
+ None, None,
+ 'failed to construct timestamp from "{}"'.format(node.value),
+ node.start_mark)
values = match.groupdict()
year = int(values['year'])
month = int(values['month'])
@@ -1429,7 +1437,15 @@ class RoundTripConstructor(SafeConstructor):
def construct_yaml_timestamp(self, node, values=None):
# type: (Any, Any) -> Any
- match = self.timestamp_regexp.match(node.value)
+ try:
+ match = self.timestamp_regexp.match(node.value)
+ except TypeError:
+ match = None
+ if match is None:
+ raise ConstructorError(
+ None, None,
+ 'failed to construct timestamp from "{}"'.format(node.value),
+ node.start_mark)
values = match.groupdict()
if not values['hour']:
return SafeConstructor.construct_yaml_timestamp(self, node, values)