Search in sources :

Example 11 with LocationAwareException

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

the class DefaultExceptionAnalyserTest method usesDeepestScriptExceptionException.

@Test
public void usesDeepestScriptExceptionException() {
    Throwable cause = new GradleScriptException("broken", new RuntimeException());
    Throwable failure = new GradleScriptException("broken", new RuntimeException(cause));
    Throwable transformedFailure = analyser().transform(failure);
    assertThat(transformedFailure, instanceOf(LocationAwareException.class));
    LocationAwareException gse = (LocationAwareException) transformedFailure;
    assertThat(gse.getCause(), sameInstance(cause));
}
Also used : LocationAwareException(org.gradle.internal.exceptions.LocationAwareException) GradleScriptException(org.gradle.api.GradleScriptException) Test(org.junit.Test)

Example 12 with LocationAwareException

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

the class DefaultExceptionAnalyserTest method doesNotAddLocationWhenLocationCannotBeDetermined.

@Test
public void doesNotAddLocationWhenLocationCannotBeDetermined() {
    Throwable failure = new ContextualException();
    Throwable transformedFailure = analyser().transform(failure);
    assertThat(transformedFailure, instanceOf(LocationAwareException.class));
    LocationAwareException gse = (LocationAwareException) transformedFailure;
    assertThat(gse.getSourceDisplayName(), nullValue());
    assertThat(gse.getLineNumber(), nullValue());
}
Also used : LocationAwareException(org.gradle.internal.exceptions.LocationAwareException) Test(org.junit.Test)

Example 13 with LocationAwareException

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

the class DefaultExceptionAnalyserTest method addsLocationInfoFromDeepestStackFrameWithMatchingSourceFileAndLineInformation.

@Test
public void addsLocationInfoFromDeepestStackFrameWithMatchingSourceFileAndLineInformation() {
    Throwable failure = new ContextualException();
    failure.setStackTrace(toArray(elementWithNoSourceFile, elementWithNoLineNumber, otherElement, element, 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 14 with LocationAwareException

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

the class DefaultExceptionAnalyserTest method wrapsContextualExceptionWithLocationAwareException.

@Test
public void wrapsContextualExceptionWithLocationAwareException() {
    Throwable failure = new ContextualException();
    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(), isEmpty());
}
Also used : LocationAwareException(org.gradle.internal.exceptions.LocationAwareException) Test(org.junit.Test)

Example 15 with LocationAwareException

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

the class DefaultPluginRequestApplicator method resolveToFoundResult.

private Result resolveToFoundResult(PluginResolver effectivePluginResolver, PluginRequestInternal request) {
    Result result = new Result(request);
    try {
        effectivePluginResolver.resolve(request, result);
    } catch (Exception e) {
        throw new LocationAwareException(new GradleException(String.format("Error resolving plugin %s", request.getDisplayName()), e), request.getScriptDisplayName(), request.getLineNumber());
    }
    if (!result.isFound()) {
        String message = buildNotFoundMessage(request, result);
        Exception exception = new UnknownPluginException(message);
        throw new LocationAwareException(exception, request.getScriptDisplayName(), request.getLineNumber());
    }
    return result;
}
Also used : LocationAwareException(org.gradle.internal.exceptions.LocationAwareException) GradleException(org.gradle.api.GradleException) UnknownPluginException(org.gradle.api.plugins.UnknownPluginException) GradleException(org.gradle.api.GradleException) UnknownPluginException(org.gradle.api.plugins.UnknownPluginException) LocationAwareException(org.gradle.internal.exceptions.LocationAwareException) InvalidPluginException(org.gradle.api.plugins.InvalidPluginException) PluginResolutionResult(org.gradle.plugin.use.resolve.internal.PluginResolutionResult)

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