Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only check relevant errors when preloading package #4066

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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