use of com.google.devtools.build.skyframe.ErrorInfo in project bazel by bazelbuild.
the class SkyframeBuilder method processResult.
/**
* Process the Skyframe update, taking into account the keepGoing setting.
*
* <p>Returns optional {@link ExitCode} based on following conditions: 1. null, if result had no
* errors. 2. Optional.absent(), if result had errors but none of the errors specified an exit
* code. 3. Optional.of(e), if result had errors and one of them specified exit code 'e'. Throws
* on fail-fast failures.
*/
@Nullable
private static Optional<ExitCode> processResult(ExtendedEventHandler eventHandler, EvaluationResult<?> result, boolean keepGoing, SkyframeExecutor skyframeExecutor) throws BuildFailedException, TestExecException {
if (result.hasError()) {
for (Map.Entry<SkyKey, ErrorInfo> entry : result.errorMap().entrySet()) {
Iterable<CycleInfo> cycles = entry.getValue().getCycleInfo();
skyframeExecutor.reportCycles(eventHandler, cycles, entry.getKey());
}
if (result.getCatastrophe() != null) {
rethrow(result.getCatastrophe());
}
if (keepGoing) {
// If build fails and keepGoing is true, an exit code is assigned using reported errors
// in the following order:
// 1. First infrastructure error with non-null exit code
// 2. First non-infrastructure error with non-null exit code
// 3. Null (later default to 1)
ExitCode exitCode = null;
for (Map.Entry<SkyKey, ErrorInfo> error : result.errorMap().entrySet()) {
Throwable cause = error.getValue().getException();
if (cause instanceof ActionExecutionException) {
ActionExecutionException actionExecutionCause = (ActionExecutionException) cause;
ExitCode code = actionExecutionCause.getExitCode();
// a lower 'reporting' priority.
if (ExitCodeComparator.INSTANCE.compare(code, exitCode) > 0) {
exitCode = code;
}
}
}
return Optional.fromNullable(exitCode);
}
ErrorInfo errorInfo = Preconditions.checkNotNull(result.getError(), result);
Exception exception = errorInfo.getException();
if (exception == null) {
Preconditions.checkState(!Iterables.isEmpty(errorInfo.getCycleInfo()), errorInfo);
// cycles above.
throw new BuildFailedException(null, /*hasCatastrophe=*/
false);
} else {
rethrow(exception);
}
}
return null;
}
use of com.google.devtools.build.skyframe.ErrorInfo in project bazel by bazelbuild.
the class SkylarkImportLookupFunctionTest method testSkylarkImportLookupNoBuildFile.
@Test
public void testSkylarkImportLookupNoBuildFile() throws Exception {
scratch.file("pkg/ext.bzl", "");
SkyKey skylarkImportLookupKey = SkylarkImportLookupValue.key(Label.parseAbsoluteUnchecked("//pkg:ext.bzl"), false);
EvaluationResult<SkylarkImportLookupValue> result = SkyframeExecutorTestUtils.evaluate(getSkyframeExecutor(), skylarkImportLookupKey, /*keepGoing=*/
false, reporter);
assertTrue(result.hasError());
ErrorInfo errorInfo = result.getError(skylarkImportLookupKey);
String errorMessage = errorInfo.getException().getMessage();
assertEquals("Extension file not found. Unable to load package for '//pkg:ext.bzl': " + "BUILD file not found on package path", errorMessage);
}
use of com.google.devtools.build.skyframe.ErrorInfo in project bazel by bazelbuild.
the class SkylarkImportLookupFunctionTest method testSkylarkImportLookupNoBuildFileForLoad.
@Test
public void testSkylarkImportLookupNoBuildFileForLoad() throws Exception {
scratch.file("pkg2/BUILD");
scratch.file("pkg1/ext.bzl", "a = 1");
scratch.file("pkg2/ext.bzl", "load('/pkg1/ext', 'a')");
SkyKey skylarkImportLookupKey = SkylarkImportLookupValue.key(Label.parseAbsoluteUnchecked("//pkg:ext.bzl"), false);
EvaluationResult<SkylarkImportLookupValue> result = SkyframeExecutorTestUtils.evaluate(getSkyframeExecutor(), skylarkImportLookupKey, /*keepGoing=*/
false, reporter);
assertTrue(result.hasError());
ErrorInfo errorInfo = result.getError(skylarkImportLookupKey);
String errorMessage = errorInfo.getException().getMessage();
assertEquals("Extension file not found. Unable to load package for '//pkg:ext.bzl': " + "BUILD file not found on package path", errorMessage);
}
use of com.google.devtools.build.skyframe.ErrorInfo in project bazel by bazelbuild.
the class ASTFileLookupFunctionTest method testLoadWithNonExistentBuildFile.
@Test
public void testLoadWithNonExistentBuildFile() throws Exception {
invalidatePackages();
SkyKey skyKey = ASTFileLookupValue.key(Label.parseAbsoluteUnchecked("@a_remote_repo//remote_pkg:BUILD"));
EvaluationResult<ASTFileLookupValue> result = SkyframeExecutorTestUtils.evaluate(getSkyframeExecutor(), skyKey, /*keepGoing=*/
false, reporter);
ErrorInfo errorInfo = result.getError(skyKey);
Throwable e = errorInfo.getException();
assertEquals(skyKey, errorInfo.getRootCauseOfException());
assertThat(e).isInstanceOf(ErrorReadingSkylarkExtensionException.class);
assertThat(e.getMessage()).contains("no such package '@a_remote_repo//remote_pkg'");
}
use of com.google.devtools.build.skyframe.ErrorInfo in project bazel by bazelbuild.
the class PackageFunctionTest method testNonExistingSkylarkExtension.
@Test
public void testNonExistingSkylarkExtension() throws Exception {
reporter.removeHandler(failFastHandler);
scratch.file("test/skylark/BUILD", "load('/test/skylark/bad_extension', 'some_symbol')", "genrule(name = gr,", " outs = ['out.txt'],", " cmd = 'echo hello >@')");
invalidatePackages();
SkyKey skyKey = PackageValue.key(PackageIdentifier.parse("@//test/skylark"));
EvaluationResult<PackageValue> result = SkyframeExecutorTestUtils.evaluate(getSkyframeExecutor(), skyKey, /*keepGoing=*/
false, reporter);
assertTrue(result.hasError());
ErrorInfo errorInfo = result.getError(skyKey);
String expectedMsg = "error loading package 'test/skylark': " + "Extension file not found. Unable to load file '//test/skylark:bad_extension.bzl': " + "file doesn't exist or isn't a file";
assertThat(errorInfo.getException()).hasMessage(expectedMsg);
}
Aggregations