Search in sources :

Example 1 with LocationAwareException

use of org.gradle.internal.exceptions.LocationAwareException in project gradle by gradle.

the class IncludedBuildArtifactBuilder method contextualizeFailure.

private RuntimeException contextualizeFailure(BuildIdentifier buildId, ReportedException e) {
    if (e.getCause() instanceof LocationAwareException) {
        LocationAwareException lae = (LocationAwareException) e.getCause();
        IncludedBuildArtifactException wrappedCause = new IncludedBuildArtifactException("Failed to build artifacts for " + buildId, lae.getCause());
        LocationAwareException newLae = new LocationAwareException(wrappedCause, lae.getSourceDisplayName(), lae.getLineNumber());
        return new ReportedException(newLae);
    }
    return e;
}
Also used : LocationAwareException(org.gradle.internal.exceptions.LocationAwareException) ReportedException(org.gradle.initialization.ReportedException)

Example 2 with LocationAwareException

use of org.gradle.internal.exceptions.LocationAwareException in project gradle by gradle.

the class DefaultExceptionAnalyserTest method wrapsContextualMultiCauseExceptionWithLocationAwareException.

@Test
public void wrapsContextualMultiCauseExceptionWithLocationAwareException() {
    Throwable cause1 = new ContextualException();
    Throwable cause2 = new ContextualException();
    Throwable failure = new ContextualMultiCauseException(cause1, cause2);
    Throwable transformedFailure = analyser().transform(failure);
    assertThat(transformedFailure, instanceOf(LocationAwareException.class));
    LocationAwareException gse = (LocationAwareException) transformedFailure;
    assertThat(gse.getCause(), sameInstance(failure));
    assertThat(gse.getReportableCauses(), equalTo(toList(cause1, cause2)));
}
Also used : LocationAwareException(org.gradle.internal.exceptions.LocationAwareException) Test(org.junit.Test)

Example 3 with LocationAwareException

use of org.gradle.internal.exceptions.LocationAwareException in project gradle by gradle.

the class DefaultExceptionAnalyserTest method wrapsHighestContextualExceptionWithLocationAwareException.

@Test
public void wrapsHighestContextualExceptionWithLocationAwareException() {
    Throwable cause = new ContextualException();
    Throwable failure = new ContextualException(cause);
    DefaultExceptionAnalyser analyser = analyser();
    Throwable transformedFailure = analyser.transform(failure);
    assertThat(transformedFailure, instanceOf(LocationAwareException.class));
    LocationAwareException gse = (LocationAwareException) transformedFailure;
    assertThat(gse.getCause(), sameInstance(failure));
    assertThat(gse.getReportableCauses(), equalTo(toList(cause)));
}
Also used : LocationAwareException(org.gradle.internal.exceptions.LocationAwareException) Test(org.junit.Test)

Example 4 with LocationAwareException

use of org.gradle.internal.exceptions.LocationAwareException in project gradle by gradle.

the class DefaultExceptionAnalyserTest method addsLocationInfoFromDeepestCause.

@Test
public void addsLocationInfoFromDeepestCause() {
    RuntimeException cause = new RuntimeException();
    ContextualException failure = new ContextualException(new RuntimeException(cause));
    failure.setStackTrace(toArray(otherElement, callerElement));
    cause.setStackTrace(toArray(element, otherElement, callerElement));
    DefaultExceptionAnalyser analyser = analyser();
    notifyAnalyser(analyser, source);
    Throwable transformedFailure = analyser.transform(failure);
    assertThat(transformedFailure, instanceOf(LocationAwareException.class));
    LocationAwareException gse = (LocationAwareException) transformedFailure;
    assertThat(gse.getSourceDisplayName(), equalTo(source.getDisplayName()));
    assertThat(gse.getLineNumber(), equalTo(7));
}
Also used : LocationAwareException(org.gradle.internal.exceptions.LocationAwareException) Test(org.junit.Test)

Example 5 with LocationAwareException

use of org.gradle.internal.exceptions.LocationAwareException in project gradle by gradle.

the class DefaultExceptionAnalyserTest method wrapsOriginalExceptionWhenItIsNotAContextualException.

@Test
public void wrapsOriginalExceptionWhenItIsNotAContextualException() {
    Throwable failure = new RuntimeException();
    DefaultExceptionAnalyser analyser = analyser();
    Throwable transformed = analyser.transform(failure);
    assertThat(transformed, instanceOf(LocationAwareException.class));
    LocationAwareException gse = (LocationAwareException) transformed;
    assertThat(gse.getCause(), sameInstance(failure));
    assertThat(gse.getReportableCauses(), isEmpty());
}
Also used : LocationAwareException(org.gradle.internal.exceptions.LocationAwareException) Test(org.junit.Test)

Aggregations

LocationAwareException (org.gradle.internal.exceptions.LocationAwareException)16 Test (org.junit.Test)10 GradleScriptException (org.gradle.api.GradleScriptException)2 GradleException (org.gradle.api.GradleException)1 InvalidPluginException (org.gradle.api.plugins.InvalidPluginException)1 UnknownPluginException (org.gradle.api.plugins.UnknownPluginException)1 TaskExecutionException (org.gradle.api.tasks.TaskExecutionException)1 ScriptCompilationException (org.gradle.groovy.scripts.ScriptCompilationException)1 ScriptSource (org.gradle.groovy.scripts.ScriptSource)1 ReportedException (org.gradle.initialization.ReportedException)1 LinePrefixingStyledTextOutput (org.gradle.internal.logging.text.LinePrefixingStyledTextOutput)1 DefaultPluginRequest (org.gradle.plugin.management.internal.DefaultPluginRequest)1 InvalidPluginRequestException (org.gradle.plugin.management.internal.InvalidPluginRequestException)1 PluginRequestInternal (org.gradle.plugin.management.internal.PluginRequestInternal)1 PluginId (org.gradle.plugin.use.PluginId)1 PluginResolutionResult (org.gradle.plugin.use.resolve.internal.PluginResolutionResult)1