Skip to content

Commit f530da4

Browse files
authored
Improved component not found error message (#442)
* Improved component not found error message * Fixed badge * Fixed error message
1 parent afc51bf commit f530da4

File tree

7 files changed

+40
-36
lines changed

7 files changed

+40
-36
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Kora Framework
22

3-
[![Maven Central](https://maven-badges.sml.io/sonatype-central/ru.tinkoff.kora/common/badge.svg)](https://maven-badges.sml.io/sonatype-central/ru.tinkoff.kora/common)
3+
[![Maven Central](https://img.shields.io/maven-central/v/ru.tinkoff.kora/common.svg)](https://central.sonatype.com/artifact/ru.tinkoff.kora/common)
44
[![GitHub Action](https://github.com/kora-projects/kora/workflows/Build%20Master/badge.svg)](https://github.com/kora-projects/kora/actions?query=workflow%3A%22Build%20Master%22++)
55

66
Репозиторий исходного кода [фреймворка Kora](https://kora-projects.github.io/kora-docs/ru/).

json/json-annotation-processor/src/test/java/ru/tinkoff/kora/json/annotation/processor/extension/JsonKoraExtensionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface TestInterface {}
2929

3030
assertThat(compileResult.isFailed()).isTrue();
3131
assertThat(compileResult.diagnostic()).anyMatch(d -> d.getKind() == Diagnostic.Kind.ERROR
32-
&& d.getMessage(Locale.US).contains("Required dependency type wasn't found and can't be auto created: " +
32+
&& d.getMessage(Locale.US).contains("Required dependency type wasn't found in graph and can't be auto created: " +
3333
"ru.tinkoff.kora.json.common.JsonReader<ru.tinkoff.kora.json.annotation.processor.extension.packageForJsonKoraExtensionTest.testReaderFromExtensionNotFoundForInterface.TestApp.TestInterface>"));
3434
}
3535

@@ -80,7 +80,7 @@ interface TestInterface {}
8080

8181
assertThat(compileResult.isFailed()).isTrue();
8282
assertThat(compileResult.diagnostic()).anyMatch(d -> d.getKind() == Diagnostic.Kind.ERROR
83-
&& d.getMessage(Locale.US).contains("Required dependency type wasn't found and can't be auto created: " +
83+
&& d.getMessage(Locale.US).contains("Required dependency type wasn't found in graph and can't be auto created: " +
8484
"ru.tinkoff.kora.json.common.JsonWriter<ru.tinkoff.kora.json.annotation.processor.extension.packageForJsonKoraExtensionTest.testWriterFromExtensionNotFoundForInterface.TestApp.TestInterface>"));
8585
}
8686

kora-app-annotation-processor/src/main/java/ru/tinkoff/kora/kora/app/annotation/processor/GraphBuilder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,13 @@ public static ProcessingState processProcessing(ProcessingContext ctx, RoundEnvi
221221
var hints = ctx.dependencyModuleHintProvider.findHints(dependencyClaim.type(), dependencyClaim.tags());
222222
var msg = new StringBuilder();
223223
if (dependencyClaim.tags().isEmpty()) {
224-
msg.append(String.format("Required dependency type wasn't found and can't be auto created: %s.\n" +
225-
"Please check class for @%s annotation or that required module with component is plugged in.",
224+
msg.append(String.format("Required dependency type wasn't found in graph and can't be auto created: %s without tag.\n" +
225+
"Please check class for @%s annotation or that required module with component factory is plugged in.",
226226
claimTypeName, CommonClassNames.component.simpleName()));
227227
} else {
228228
var tagMsg = dependencyClaim.tags().stream().collect(Collectors.joining(", ", "@Tag(", ")"));
229-
msg.append(String.format("Required dependency type wasn't found and can't be auto created: %s with tag %s.\n" +
230-
"Please check class for @%s annotation or that required module with component is plugged in.",
229+
msg.append(String.format("Required dependency type wasn't found in graph and can't be auto created: %s with tag %s.\n" +
230+
"Please check class for @%s annotation or that required module with component factory is plugged in.",
231231
claimTypeName, tagMsg, CommonClassNames.component.simpleName()));
232232
}
233233
for (var hint : hints) {

kora-app-annotation-processor/src/test/java/ru/tinkoff/kora/kora/app/annotation/processor/DependencyTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ final class TestClass1 {}
277277
assertThat(compileResult.errors()).hasSize(1);
278278
assertThat(compileResult.errors().get(0).getMessage(Locale.ENGLISH)).startsWith(
279279
"""
280-
Required dependency type wasn't found and can't be auto created: ru.tinkoff.kora.kora.app.annotation.processor.packageForDependencyTest.testDiscoveredFinalClassDependencyTaggedDependencyNoTagOnClass.ExampleApplication.TestClass1 with tag @Tag(ru.tinkoff.kora.kora.app.annotation.processor.packageForDependencyTest.testDiscoveredFinalClassDependencyTaggedDependencyNoTagOnClass.ExampleApplication.TestClass1).
281-
Please check class for @Component annotation or that required module with component is plugged in.
280+
Required dependency type wasn't found in graph and can't be auto created: ru.tinkoff.kora.kora.app.annotation.processor.packageForDependencyTest.testDiscoveredFinalClassDependencyTaggedDependencyNoTagOnClass.ExampleApplication.TestClass1 with tag @Tag(ru.tinkoff.kora.kora.app.annotation.processor.packageForDependencyTest.testDiscoveredFinalClassDependencyTaggedDependencyNoTagOnClass.ExampleApplication.TestClass1).
281+
Please check class for @Component annotation or that required module with component factory is plugged in.
282282
""");
283283
}
284284

kora-app-annotation-processor/src/test/java/ru/tinkoff/kora/kora/app/annotation/processor/KoraAppProcessorTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ void unresolvedDependency() {
158158
assertThatThrownBy(() -> testClass(AppWithUnresolvedDependency.class))
159159
.isInstanceOfSatisfying(CompilationErrorException.class, e -> SoftAssertions.assertSoftly(s -> {
160160
s.assertThat(e.getMessage()).startsWith("""
161-
Required dependency type wasn't found and can't be auto created: ru.tinkoff.kora.kora.app.annotation.processor.app.AppWithUnresolvedDependency.Class3.
162-
Please check class for @Component annotation or that required module with component is plugged in.
161+
Required dependency type wasn't found in graph and can't be auto created: ru.tinkoff.kora.kora.app.annotation.processor.app.AppWithUnresolvedDependency.Class3 without tag.
162+
Please check class for @Component annotation or that required module with component factory is plugged in.
163163
Dependency chain:
164164
ru.tinkoff.kora.kora.app.annotation.processor.app.AppWithUnresolvedDependency.class2
165165
ru.tinkoff.kora.kora.app.annotation.processor.app.AppWithUnresolvedDependency.class1
@@ -204,14 +204,14 @@ void appWithFactory() throws Throwable {
204204
testClass(AppWithFactories9.class).init();
205205
assertThatThrownBy(() -> testClass(AppWithFactories10.class))
206206
.isInstanceOf(CompilationErrorException.class)
207-
.hasMessageStartingWith("Required dependency type wasn't found and can't be auto created: java.io.Closeable")
207+
.hasMessageStartingWith("Required dependency type wasn't found in graph and can't be auto created: java.io.Closeable")
208208
.asInstanceOf(type(CompilationErrorException.class))
209209
.extracting(CompilationErrorException::getDiagnostics, list(Diagnostic.class))
210210
.anySatisfy(d -> {
211211
assertThat(d.getKind()).isEqualTo(Diagnostic.Kind.ERROR);
212212
assertThat(d.getMessage(Locale.ENGLISH)).isEqualTo("""
213-
Required dependency type wasn't found and can't be auto created: java.io.Closeable.
214-
Please check class for @Component annotation or that required module with component is plugged in.
213+
Required dependency type wasn't found in graph and can't be auto created: java.io.Closeable without tag.
214+
Please check class for @Component annotation or that required module with component factory is plugged in.
215215
Dependency chain:
216216
ru.tinkoff.kora.kora.app.annotation.processor.app.AppWithFactories10.mock1
217217
Requested at: ru.tinkoff.kora.kora.app.annotation.processor.app.AppWithFactories10.mock1(java.io.Closeable)

kora-app-symbol-processor/src/main/kotlin/ru/tinkoff/kora/kora/app/ksp/GraphBuilder.kt

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,14 @@ object GraphBuilder {
115115
try {
116116
results.add(this.processProcessing(ctx, newProcessing, dependencyClaim))
117117
} catch (e: NewRoundException) {
118-
results.add(ProcessingState.NewRoundRequired(
119-
e.source,
120-
e.type,
121-
e.tag,
122-
e.resolving
123-
))
118+
results.add(
119+
ProcessingState.NewRoundRequired(
120+
e.source,
121+
e.type,
122+
e.tag,
123+
e.resolving
124+
)
125+
)
124126
} catch (e: UnresolvedDependencyException) {
125127
if (exception != null) {
126128
exception.addSuppressed(e)
@@ -211,14 +213,16 @@ object GraphBuilder {
211213
val hints = ctx.dependencyHintProvider.findHints(dependencyClaim.type, dependencyClaim.tags)
212214
val msg = if (dependencyClaim.tags.isEmpty()) {
213215
StringBuilder(
214-
"Required dependency type wasn't found and can't be auto created: ${dependencyClaim.type.toTypeName()}.\n" +
215-
"Please check class for @${CommonClassNames.component.canonicalName} annotation or that required module with component is plugged in."
216+
"Required dependency type wasn't found in graph and can't be auto created: ${dependencyClaim.type.toTypeName()} without tag.\n" +
217+
"Keep in mind that nullable & non nullable types are different ones.\n" +
218+
"Please check class for @${CommonClassNames.component.canonicalName} annotation or that required module with component factory is plugged in."
216219
)
217220
} else {
218221
val tagMsg = dependencyClaim.tags.joinToString(", ", "@Tag(", ")")
219222
StringBuilder(
220-
"Required dependency type wasn't found and can't be auto created: ${dependencyClaim.type.toTypeName()} with tag ${tagMsg}.\n" +
221-
"Please check class for @${CommonClassNames.component.canonicalName} annotation or that required module with component is plugged in."
223+
"Required dependency type wasn't found in graph and can't be auto created: ${dependencyClaim.type.toTypeName()} with tag ${tagMsg}.\n" +
224+
"Keep in mind that nullable & non nullable types are different ones).\n" +
225+
"Please check class for @${CommonClassNames.component.canonicalName} annotation or that required module with component factory is plugged in."
222226
)
223227
}
224228
for (hint in hints) {
@@ -332,19 +336,19 @@ object GraphBuilder {
332336
)
333337
.addFunction(
334338
FunSpec.builder("getDelegate")
335-
.addModifiers(KModifier.PRIVATE)
336-
.returns(typeName)
339+
.addModifiers(KModifier.PRIVATE)
340+
.returns(typeName)
337341
.addCode(
338342
CodeBlock.builder()
339-
.addStatement("var delegate = this.delegate")
340-
.controlFlow("if (delegate == null)") {
341-
addStatement("delegate = this.promise.get().get()!!")
342-
addStatement("this.delegate = delegate")
343-
}
344-
.addStatement("return delegate")
343+
.addStatement("var delegate = this.delegate")
344+
.controlFlow("if (delegate == null)") {
345+
addStatement("delegate = this.promise.get().get()!!")
346+
addStatement("this.delegate = delegate")
347+
}
348+
.addStatement("return delegate")
349+
.build()
350+
)
345351
.build()
346-
)
347-
.build()
348352
)
349353
for (typeParameter in claimTypeDeclaration.typeParameters) {
350354
type.addTypeVariable(typeParameter.toTypeVariableName(typeTpr))

kora-app-symbol-processor/src/test/kotlin/ru/tinkoff/kora/kora/app/ksp/KoraAppKspTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class KoraAppKspTest {
209209
.isInstanceOfSatisfying(CompilationErrorException::class.java) { e ->
210210
SoftAssertions.assertSoftly { s: SoftAssertions ->
211211
s.assertThat(e.messages)
212-
.anyMatch { it.contains("Required dependency type wasn't found and can't be auto created: ru.tinkoff.kora.kora.app.ksp.app.AppWithUnresolvedDependency.Class3") }
212+
.anyMatch { it.contains("Required dependency type wasn't found in graph and can't be auto created: ru.tinkoff.kora.kora.app.ksp.app.AppWithUnresolvedDependency.Class3") }
213213
}
214214
}
215215
}
@@ -260,7 +260,7 @@ class KoraAppKspTest {
260260
.isInstanceOfSatisfying(CompilationErrorException::class.java) { e ->
261261
SoftAssertions.assertSoftly { s: SoftAssertions ->
262262
s.assertThat(e.messages).anyMatch {
263-
it.contains("Required dependency type wasn't found and can't be auto created: java.io.Closeable")
263+
it.contains("Required dependency type wasn't found in graph and can't be auto created: java.io.Closeable")
264264
}
265265
}
266266
}

0 commit comments

Comments
 (0)