Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Unified Diff: sdk/lib/_internal/pub/lib/src/validator/pubspec_field.dart

Issue 24246002: Lazily throw pubspec parsing exceptions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/pub/lib/src/validator/pubspec_field.dart
diff --git a/sdk/lib/_internal/pub/lib/src/validator/pubspec_field.dart b/sdk/lib/_internal/pub/lib/src/validator/pubspec_field.dart
index e9d2d35452f87f98e005fc7ee28f5c5db7a14667..d43407cf10fa372c1d263e58242357d3c35604ef 100644
--- a/sdk/lib/_internal/pub/lib/src/validator/pubspec_field.dart
+++ b/sdk/lib/_internal/pub/lib/src/validator/pubspec_field.dart
@@ -39,21 +39,41 @@ class PubspecFieldValidator extends Validator {
}
}
- var homepage = pubspec.fields['homepage'];
- if (homepage == null) {
- errors.add('Your pubspec.yaml is missing a "homepage" field.');
- }
+ _validateFieldExists('description');
+ _validateFieldExists('version');
+ _validateFieldExists('homepage');
+ _validateFieldUrl('homepage');
+ _validateFieldUrl('documentation');
- var description = pubspec.fields['description'];
- if (description == null) {
- errors.add('Your pubspec.yaml is missing a "description" field.');
+ // Pubspec errors are detected lazily, so we make sure there aren't any
+ // here.
+ for (var error in pubspec.allErrors) {
+ errors.add('In your pubspec.yaml, ${error.message}');
}
- var version = pubspec.fields['version'];
- if (version == null) {
- errors.add('Your pubspec.yaml is missing a "version" field.');
+ return new Future.value();
+ }
+
+ void _validateFieldExists(String field) {
+ if (entrypoint.root.pubspec.fields[field] != null) return;
+ errors.add('Your pubspec.yaml is missing a "$field" field.');
+ }
+
+ /// Adds an error if the given [url] for [field] is invalid.
+ void _validateFieldUrl(String field) {
+ var url = entrypoint.root.pubspec.fields[field];
+ if (url == null) return;
+
+ if (url is! String) {
+ errors.add('Your pubspec.yaml\'s "$field" field must be a string, but '
+ 'it was "$url".');
+ return;
}
- return new Future.value();
+ var goodScheme = new RegExp(r'^https?:');
+ if (!goodScheme.hasMatch(url)) {
+ errors.add('Your pubspec.yaml\'s "$field" field must be an "http:" or '
+ '"https:" URL, but it was "$url".');
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698