Skip to content

Commit 7afddc0

Browse files
committed
better error messages
1 parent e604e82 commit 7afddc0

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

lib/carbon/util.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -342,19 +342,17 @@ class TaggedSeries(object):
342342
def validateTagAndValue(cls, tag, value):
343343
"""validate the given tag / value based on the specs in the documentation"""
344344
if len(tag) == 0 or len(value) == 0:
345-
return False
345+
raise Exception('Tag/Value may not be empty')
346346

347347
for char in cls.prohibitedTagChars:
348348
if char in tag:
349-
return False
349+
raise Exception('Prohibited char "{char}" in tag "{tag}"'.format(char=char, tag=tag))
350350

351351
if ';' in value:
352-
return False
352+
raise Exception('Character ";" is not allowed in tag value "{value}"'.format(value=value))
353353

354354
if value[0] == '~':
355-
return False
356-
357-
return True
355+
raise Exception('Tags are not allowed to start with "~" in tag "{tag}"'.format(tag=tag))
358356

359357
@classmethod
360358
def parse(cls, path):
@@ -385,8 +383,7 @@ def parse_openmetrics(cls, path):
385383
tag = m.group(1)
386384
value = m.group(2).replace(r'\"', '"').replace(r'\\', '\\')
387385

388-
if not cls.validateTagAndValue(tag, value):
389-
raise Exception('Tag/Value contains invalid characters: %s/%s' % (tag, value))
386+
cls.validateTagAndValue(tag, value)
390387

391388
tags[tag] = value
392389
rawtags = rawtags[len(m.group(0)):]
@@ -410,8 +407,7 @@ def parse_carbon(cls, path):
410407
if len(tag) != 2 or not tag[0]:
411408
raise Exception('Cannot parse path %s, invalid segment %s' % (path, segment))
412409

413-
if not cls.validateTagAndValue(*tag):
414-
raise Exception('Tag/Value contains invalid characters: %s/%s' % (tag[0], tag[1]))
410+
cls.validateTagAndValue(*tag)
415411

416412
tags[tag[0]] = tag[1]
417413

0 commit comments

Comments
 (0)