Skip to content

Commit

Permalink
Only check relevant errors when preloading package (#4066)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigurdm authored Nov 30, 2023
1 parent 3d4a298 commit 531fcd4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
46 changes: 33 additions & 13 deletions lib/src/pubspec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,9 @@ class Pubspec extends PubspecBase {
}
}

/// Returns a list of most errors in this pubspec.
///
/// This will return at most one error for each field.
List<SourceSpanApplicationException> get allErrors {
List<SourceSpanApplicationException> _collectErrorsFor(
List<dynamic Function()> toCheck,
) {
var errors = <SourceSpanApplicationException>[];
void collectError(void Function() fn) {
try {
Expand All @@ -375,18 +374,39 @@ class Pubspec extends PubspecBase {
}
}

collectError(() => name);
collectError(() => version);
collectError(() => dependencies);
collectError(() => devDependencies);
collectError(() => publishTo);
collectError(() => executables);
collectError(() => falseSecrets);
collectError(() => sdkConstraints);
collectError(() => ignoredAdvisories);
for (final fn in toCheck) {
collectError(fn);
}
return errors;
}

/// Returns a list of errors relevant to consuming this pubspec as a dependency
///
/// This will return at most one error for each field.
List<SourceSpanApplicationException> get dependencyErrors =>
_collectErrorsFor([
() => name,
() => version,
() => dependencies,
() => executables,
() => ignoredAdvisories,
]);

/// Returns a list of most errors in this pubspec.
///
/// This will return at most one error for each field.
List<SourceSpanApplicationException> get allErrors => _collectErrorsFor([
() => name,
() => version,
() => dependencies,
() => devDependencies,
() => publishTo,
() => executables,
() => falseSecrets,
() => sdkConstraints,
() => ignoredAdvisories,
]);

/// Returns the type of dependency from this package onto [name].
DependencyType dependencyType(String? name) {
if (dependencies.containsKey(name)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/source/hosted.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,7 @@ See $contentHashesDocumentationUrl.
final Pubspec pubspec;
try {
pubspec = Pubspec.load(tempDir, cache.sources);
final errors = pubspec.allErrors;
final errors = pubspec.dependencyErrors;
if (errors.isNotEmpty) {
throw errors.first;
}
Expand Down

0 comments on commit 531fcd4

Please sign in to comment.