Skip to content

Commit

Permalink
Clean up a little bit around PackageFunction.PackageFunctionException…
Browse files Browse the repository at this point in the history
… creation.

PiperOrigin-RevId: 408983493
  • Loading branch information
janakdr authored and copybara-github committed Nov 10, 2021
1 parent 085ce0c commit a88dd85
Showing 1 changed file with 14 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -565,27 +565,15 @@ public SkyValue compute(SkyKey key, Environment env)
packageLookupValue.getRoot(), packageId, pkgBuilder, env);
} catch (InternalInconsistentFilesystemException e) {
packageFunctionCache.invalidate(packageId);
PackageLoading.Code packageLoadingCode =
e.isTransient()
? PackageLoading.Code.TRANSIENT_INCONSISTENT_FILESYSTEM_ERROR
: PackageLoading.Code.PERSISTENT_INCONSISTENT_FILESYSTEM_ERROR;
throw new PackageFunctionException(
e.toNoSuchPackageException(packageLoadingCode),
e.isTransient() ? Transience.TRANSIENT : Transience.PERSISTENT);
throw e.throwPackageFunctionException();
}
Set<SkyKey> globKeys = packageCacheEntry.globDepKeys;
try {
handleGlobDepsAndPropagateFilesystemExceptions(
packageId, globKeys, env, pkgBuilder.containsErrors());
} catch (InternalInconsistentFilesystemException e) {
packageFunctionCache.invalidate(packageId);
PackageLoading.Code packageLoadingCode =
e.isTransient()
? PackageLoading.Code.TRANSIENT_INCONSISTENT_FILESYSTEM_ERROR
: PackageLoading.Code.PERSISTENT_INCONSISTENT_FILESYSTEM_ERROR;
throw new PackageFunctionException(
e.toNoSuchPackageException(packageLoadingCode),
e.isTransient() ? Transience.TRANSIENT : Transience.PERSISTENT);
throw e.throwPackageFunctionException();
} catch (FileSymlinkException e) {
packageFunctionCache.invalidate(packageId);
String message = "Symlink issue while evaluating globs: " + e.getUserFriendlyMessage();
Expand Down Expand Up @@ -1550,15 +1538,19 @@ public boolean isTransient() {
return isTransient;
}

private NoSuchPackageException toNoSuchPackageException(
PackageLoading.Code packageLoadingCode) {
return PackageFunctionException.builder()
private PackageFunctionException throwPackageFunctionException()
throws PackageFunctionException {
throw PackageFunctionException.builder()
.setType(PackageFunctionException.Type.NO_SUCH_PACKAGE)
.setPackageIdentifier(packageIdentifier)
.setMessage(this.getMessage())
.setException((Exception) this.getCause())
.setPackageLoadingCode(packageLoadingCode)
.buildCause();
.setPackageLoadingCode(
isTransient()
? Code.TRANSIENT_INCONSISTENT_FILESYSTEM_ERROR
: Code.PERSISTENT_INCONSISTENT_FILESYSTEM_ERROR)
.setTransience(isTransient() ? Transience.TRANSIENT : Transience.PERSISTENT)
.build();
}
}

Expand All @@ -1580,7 +1572,7 @@ static Builder builder() {
* contains a myriad of different types of exceptions that extend NoSuchPackageException for
* different scenarios.
*/
static enum Type {
enum Type {
BUILD_FILE_CONTAINS_ERRORS {
@Override
BuildFileContainsErrorsException create(
Expand Down Expand Up @@ -1640,12 +1632,12 @@ Builder setPackageIdentifier(PackageIdentifier packageIdentifier) {
return this;
}

Builder setTransience(Transience transience) {
private Builder setTransience(Transience transience) {
this.transience = transience;
return this;
}

Builder setException(Exception exception) {
private Builder setException(Exception exception) {
this.exception = exception;
return this;
}
Expand Down

0 comments on commit a88dd85

Please sign in to comment.