Skip to content

Commit

Permalink
Add handling for invalid packages as well as invalid targets.
Browse files Browse the repository at this point in the history
Work towards platform-based flags: #19409.

PiperOrigin-RevId: 606321858
Change-Id: If6d7b1901475dcc199d543407552d634c9359166
  • Loading branch information
katre authored and copybara-github committed Feb 12, 2024
1 parent d2f9559 commit 10fa715
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.devtools.build.lib.cmdline.Label.PackageContext;
import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.cmdline.TargetParsingException;
import com.google.devtools.build.lib.packages.NoSuchPackageException;
import com.google.devtools.build.lib.packages.NoSuchTargetException;
import com.google.devtools.build.lib.packages.Target;
import com.google.devtools.build.lib.runtime.StarlarkOptionsParser;
Expand Down Expand Up @@ -109,14 +110,14 @@ public Target loadBuildSetting(String name)
} catch (LabelSyntaxException e) {
throw new IllegalArgumentException(e);
}
SkyKey pkgKey = asLabel.getPackageIdentifier();
PackageValue pkg = (PackageValue) env.getValue(pkgKey);
if (pkg == null) {
return null;
}
try {
SkyKey pkgKey = asLabel.getPackageIdentifier();
PackageValue pkg = (PackageValue) env.getValueOrThrow(pkgKey, NoSuchPackageException.class);
if (pkg == null) {
return null;
}
return pkg.getPackage().getTarget(asLabel.getName());
} catch (NoSuchTargetException e) {
} catch (NoSuchPackageException | NoSuchTargetException e) {
throw new TargetParsingException(
String.format("Failed to load %s", name), e, DEPENDENCY_NOT_FOUND);
}
Expand Down

0 comments on commit 10fa715

Please sign in to comment.