From 5fd1cfadc77c99673b2bd52a27deddca37b818b6 Mon Sep 17 00:00:00 2001 From: Sigurd Meldgaard Date: Thu, 30 Nov 2023 10:35:01 +0000 Subject: [PATCH] Only check relevant errors when preloading package --- lib/src/pubspec.dart | 46 +++++++++++++++++++++++++++----------- lib/src/source/hosted.dart | 2 +- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/lib/src/pubspec.dart b/lib/src/pubspec.dart index f65c8ab20..d8ddd9f15 100644 --- a/lib/src/pubspec.dart +++ b/lib/src/pubspec.dart @@ -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 get allErrors { + List _collectErrorsFor( + List toCheck, + ) { var errors = []; void collectError(void Function() fn) { try { @@ -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 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 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)) { diff --git a/lib/src/source/hosted.dart b/lib/src/source/hosted.dart index 01b2ff4ee..2dea58d77 100644 --- a/lib/src/source/hosted.dart +++ b/lib/src/source/hosted.dart @@ -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; }