@@ -342,19 +342,17 @@ class TaggedSeries(object):
342
342
def validateTagAndValue (cls , tag , value ):
343
343
"""validate the given tag / value based on the specs in the documentation"""
344
344
if len (tag ) == 0 or len (value ) == 0 :
345
- return False
345
+ raise Exception ( 'Tag/Value may not be empty' )
346
346
347
347
for char in cls .prohibitedTagChars :
348
348
if char in tag :
349
- return False
349
+ raise Exception ( 'Prohibited char "{char}" in tag "{tag}"' . format ( char = char , tag = tag ))
350
350
351
351
if ';' in value :
352
- return False
352
+ raise Exception ( 'Character ";" is not allowed in tag value "{value}"' . format ( value = value ))
353
353
354
354
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 ))
358
356
359
357
@classmethod
360
358
def parse (cls , path ):
@@ -385,8 +383,7 @@ def parse_openmetrics(cls, path):
385
383
tag = m .group (1 )
386
384
value = m .group (2 ).replace (r'\"' , '"' ).replace (r'\\' , '\\ ' )
387
385
388
- if not cls .validateTagAndValue (tag , value ):
389
- raise Exception ('Tag/Value contains invalid characters: %s/%s' % (tag , value ))
386
+ cls .validateTagAndValue (tag , value )
390
387
391
388
tags [tag ] = value
392
389
rawtags = rawtags [len (m .group (0 )):]
@@ -410,8 +407,7 @@ def parse_carbon(cls, path):
410
407
if len (tag ) != 2 or not tag [0 ]:
411
408
raise Exception ('Cannot parse path %s, invalid segment %s' % (path , segment ))
412
409
413
- if not cls .validateTagAndValue (* tag ):
414
- raise Exception ('Tag/Value contains invalid characters: %s/%s' % (tag [0 ], tag [1 ]))
410
+ cls .validateTagAndValue (* tag )
415
411
416
412
tags [tag [0 ]] = tag [1 ]
417
413
0 commit comments