Index: lib/src/backend/metadata.dart |
diff --git a/lib/src/backend/metadata.dart b/lib/src/backend/metadata.dart |
index 0a45aead2a34dff689cbcc1655619f6c93e8d9ea..76681a303c9dd48b3c2ec126ceed10553321e765 100644 |
--- a/lib/src/backend/metadata.dart |
+++ b/lib/src/backend/metadata.dart |
@@ -118,7 +118,11 @@ class Metadata { |
onPlatform = onPlatform == null |
? const {} |
: new UnmodifiableMapView(onPlatform), |
- tags = tags == null ? new Set() : new UnmodifiableSetView(tags.toSet()); |
+ tags = tags == null |
+ ? new Set() |
+ : new UnmodifiableSetView(tags.toSet()) { |
+ _validateTags(); |
+ } |
/// Creates a new Metadata, but with fields parsed from caller-friendly values |
/// where applicable. |
@@ -139,6 +143,8 @@ class Metadata { |
throw new ArgumentError( |
'"skip" must be a String or a bool, was "$skip".'); |
} |
+ |
+ _validateTags(); |
} |
/// Deserializes the result of [Metadata.serialize] into a new [Metadata]. |
@@ -164,6 +170,22 @@ class Metadata { |
new Duration(microseconds: serialized['duration'])); |
} |
+ /// Throws an [ArgumentError] if any tags in [tags] aren't hyphenated |
+ /// identifiers. |
+ void _validateTags() { |
+ var invalidTags = tags |
+ .where((tag) => !tag.contains(anchoredHyphenatedIdentifier)) |
+ .map((tag) => '"$tag"') |
+ .toList(); |
+ |
+ if (invalidTags.isEmpty) return; |
+ |
+ throw new ArgumentError( |
+ "Invalid ${pluralize('tag', invalidTags.length)} " |
+ "${toSentence(invalidTags)}. Tags must be (optionally hyphenated) " |
+ "Dart identifiers."); |
+ } |
+ |
/// Return a new [Metadata] that merges [this] with [other]. |
/// |
/// If the two [Metadata]s have conflicting properties, [other] wins. |