Skip to content

Commit

Permalink
use VerificationException instead of GradleException, fixes #290 (#294)
Browse files Browse the repository at this point in the history
Develocity can classify exceptions into verification
and non-verification exceptions. Using
VerificationException ensures correct classification
for non-infrastructure related failures.
  • Loading branch information
nebulon42 authored Jan 29, 2025
1 parent ce2ede4 commit 25fc158
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.jraska.module.graph.assertion

import com.jraska.module.graph.DependencyGraph
import org.gradle.api.GradleException
import org.gradle.api.tasks.VerificationException
import java.io.Serializable

class ModuleTreeHeightAssert(
Expand All @@ -20,15 +20,15 @@ class ModuleTreeHeightAssert(
val height = dependencyGraph.heightOf(moduleName)
if (height > maxHeight) {
val longestPath = dependencyGraph.longestPath(moduleName)
throw GradleException("Module $moduleName is allowed to have maximum height of $maxHeight, but has $height, problematic dependencies: ${longestPath.pathString()}")
throw VerificationException("Module $moduleName is allowed to have maximum height of $maxHeight, but has $height, problematic dependencies: ${longestPath.pathString()}")
}
}

private fun assertWholeGraphHeight(dependencyGraph: DependencyGraph) {
val height = dependencyGraph.height()
if (height > maxHeight) {
val longestPath = dependencyGraph.longestPath()
throw GradleException("Module Graph is allowed to have maximum height of $maxHeight, but has $height, problematic dependencies: ${longestPath.pathString()}")
throw VerificationException("Module Graph is allowed to have maximum height of $maxHeight, but has $height, problematic dependencies: ${longestPath.pathString()}")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.jraska.module.graph.assertion

import com.jraska.module.graph.DependencyGraph
import com.jraska.module.graph.Parse
import org.gradle.api.GradleException
import org.gradle.api.tasks.VerificationException

class OnlyAllowedAssert(
private val allowedDependencies: Array<String>,
Expand All @@ -18,7 +18,7 @@ class OnlyAllowedAssert(

if (disallowedDependencies.isNotEmpty()) {
val allowedRules = allowedDependencies.joinToString(", ") { "'$it'" }
throw GradleException("$disallowedDependencies not allowed by any of [$allowedRules]")
throw VerificationException("$disallowedDependencies not allowed by any of [$allowedRules]")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.jraska.module.graph.assertion
import com.jraska.module.graph.DependencyGraph
import com.jraska.module.graph.Parse
import com.jraska.module.graph.RegexpDependencyMatcher
import org.gradle.api.GradleException
import org.gradle.api.tasks.VerificationException

class RestrictedDependenciesAssert(
private val errorMatchers: Array<String>,
Expand All @@ -20,7 +20,7 @@ class RestrictedDependenciesAssert(
}.filter { it.second.isNotEmpty() }

if (failedDependencies.isNotEmpty()) {
throw GradleException(buildErrorMessage(failedDependencies))
throw VerificationException(buildErrorMessage(failedDependencies))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.jraska.module.graph.assertion

import com.jraska.module.graph.DependencyGraph
import org.gradle.api.GradleException
import org.gradle.api.tasks.VerificationException
import org.junit.Test

class ModuleTreeHeightAssertTest {
Expand All @@ -12,7 +12,7 @@ class ModuleTreeHeightAssertTest {
ModuleTreeHeightAssert("app", 3).assert(dependencyGraph)
}

@Test(expected = GradleException::class)
@Test(expected = VerificationException::class)
fun failsOnTooLargeHeight() {
val dependencyGraph = testGraph()

Expand All @@ -26,7 +26,7 @@ class ModuleTreeHeightAssertTest {
ModuleTreeHeightAssert(null, 3).assert(dependencyGraph)
}

@Test(expected = GradleException::class)
@Test(expected = VerificationException::class)
fun failsOnTooHighGraphHeight() {
val dependencyGraph = testGraph()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.jraska.module.graph.assertion

import com.jraska.module.graph.DependencyGraph
import org.gradle.api.GradleException
import org.gradle.api.tasks.VerificationException
import org.junit.Test

class OnlyAllowedAssertTest {
@Test(expected = GradleException::class)
@Test(expected = VerificationException::class)
fun failsWithNoMatchingMatchers() {
val dependencyGraph = testGraph()

Expand Down Expand Up @@ -33,7 +33,7 @@ class OnlyAllowedAssertTest {
OnlyAllowedAssert(allowedDependencies).assert(dependencyGraph)
}

@Test(expected = GradleException::class)
@Test(expected = VerificationException::class)
fun failsWhenOneNotAllowed() {
val dependencies = testGraph().dependencyPairs().toMutableList().apply { add("api" to "lib2") }
val dependencyGraph = DependencyGraph.create(dependencies)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.jraska.module.graph.assertion

import com.jraska.module.graph.DependencyGraph
import org.gradle.api.GradleException
import org.gradle.api.tasks.VerificationException
import org.junit.Test

class RestrictedDependenciesAssertTest {
Expand All @@ -12,14 +12,14 @@ class RestrictedDependenciesAssertTest {
RestrictedDependenciesAssert(emptyArray()).assert(dependencyGraph)
}

@Test(expected = GradleException::class)
@Test(expected = VerificationException::class)
fun failsWhenFeatureCannotDependOnLib() {
val dependencyGraph = testGraph()

RestrictedDependenciesAssert(arrayOf("feature -X> lib2")).assert(dependencyGraph)
}

@Test(expected = GradleException::class)
@Test(expected = VerificationException::class)
fun failsWhenLibCannotDependOnAndroid() {
val dependencyGraph = testGraph()

Expand Down Expand Up @@ -48,7 +48,7 @@ class RestrictedDependenciesAssertTest {
).assert(dependencyGraph)
}

@Test(expected = GradleException::class)
@Test(expected = VerificationException::class)
fun failsWithMatchersToAlias() {
val dependencyGraph = DependencyGraph.create(
"app" to "feature",
Expand Down

0 comments on commit 25fc158

Please sign in to comment.