Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve exception message #4823

Merged
merged 4 commits into from Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -94,11 +94,17 @@ class AnalyzerSpec {
testFile,
yamlConfig("configs/config-value-type-correct.yml")
)
val analyzer = Analyzer(settings, listOf(FaultyRuleSetProvider()), emptyList())
var analyzer = Analyzer(settings, listOf(FaultyRuleSetProvider(false)), emptyList())

assertThatThrownBy { settings.use { analyzer.run(listOf(compileForTest(testFile))) } }
.hasCauseInstanceOf(IllegalStateException::class.java)
.hasMessageContaining(FaultyRule::class.java.name)

analyzer = Analyzer(settings, listOf(FaultyRuleSetProvider(true)), emptyList())

assertThatThrownBy { settings.use { analyzer.run(listOf(compileForTest(testFile))) } }
.hasCauseInstanceOf(IllegalStateException::class.java)
.hasMessageContaining("Unknown.")
}
}
}
Expand All @@ -121,14 +127,20 @@ private class MaxLineLength(config: Config, threshold: Int?) : Rule(config) {
}
}

private class FaultyRuleSetProvider : RuleSetProvider {
private class FaultyRuleSetProvider(private val isStackTraceEmpty: Boolean) : RuleSetProvider {
VitalyVPinchuk marked this conversation as resolved.
Show resolved Hide resolved
override val ruleSetId: String = "style"
override fun instance(config: Config) = RuleSet(ruleSetId, listOf(FaultyRule(config)))
override fun instance(config: Config) = RuleSet(ruleSetId, listOf(FaultyRule(config, isStackTraceEmpty)))
}

private class FaultyRule(config: Config) : Rule(config) {
private class FaultyRule(config: Config, private val isStackTraceEmpty: Boolean) : Rule(config) {
override val issue = Issue(this::class.java.simpleName, Severity.Style, "", Debt.FIVE_MINS)
override fun visitKtFile(file: KtFile) {
error("Deliberately triggered error.")
throw object : IllegalStateException("Deliberately triggered error.") {
init {
if (isStackTraceEmpty) {
stackTrace = emptyArray()
}
}
}
}
}
Expand Up @@ -4,3 +4,4 @@ style:
maxLineLength: 120
FaultyRule:
active: true
isStacktraceEmpty: false