Skip to content

Commit

Permalink
chore: improve error message for duplicated PWA annotation (#19916)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollovati authored Sep 10, 2024
1 parent 2318e57 commit 2c4c9fc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
import com.vaadin.flow.theme.NoTheme;
import com.vaadin.flow.theme.ThemeDefinition;

import static com.vaadin.flow.server.frontend.scanner.FrontendClassVisitor.DEV;
import static com.vaadin.flow.server.frontend.scanner.FrontendClassVisitor.VALUE;
import static com.vaadin.flow.server.frontend.scanner.FrontendClassVisitor.VERSION;
import static com.vaadin.flow.server.frontend.scanner.FrontendClassVisitor.DEV;

/**
* Represents the class dependency tree of the application.
Expand Down Expand Up @@ -742,14 +742,19 @@ private void computePwaConfiguration() throws ClassNotFoundException {
.getAnnotatedClasses(PWA.class.getName())) {
if (!Arrays.asList(hopefullyAppShellClass.getInterfaces())
.contains(appShellConfiguratorClass)) {
throw new IllegalStateException(ERROR_INVALID_PWA_ANNOTATION);
throw new IllegalStateException(ERROR_INVALID_PWA_ANNOTATION
+ " " + hopefullyAppShellClass.getName()
+ " does not implement "
+ AppShellConfigurator.class.getSimpleName());
}
pwaVisitor.visitClass(hopefullyAppShellClass.getName());
}

Set<String> dependencies = pwaVisitor.getValues("name");
if (dependencies.size() > 1) {
throw new IllegalStateException(ERROR_INVALID_PWA_ANNOTATION);
throw new IllegalStateException(ERROR_INVALID_PWA_ANNOTATION
+ " Found " + dependencies.size() + " implementations: "
+ dependencies);
}
if (dependencies.isEmpty()) {
this.pwaConfiguration = new PwaConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,15 +520,20 @@ private PwaConfiguration discoverPwa() {
if (annotatedClasses.isEmpty()) {
return new PwaConfiguration();
} else if (annotatedClasses.size() != 1) {
throw new IllegalStateException(ERROR_INVALID_PWA_ANNOTATION);
throw new IllegalStateException(ERROR_INVALID_PWA_ANNOTATION
+ " Found " + annotatedClasses.size()
+ " implementations: " + annotatedClasses);
}

Class<?> hopefullyAppShellClass = annotatedClasses.iterator()
.next();
if (!Arrays.stream(hopefullyAppShellClass.getInterfaces())
.map(Class::getName).collect(Collectors.toList())
.contains(AppShellConfigurator.class.getName())) {
throw new IllegalStateException(ERROR_INVALID_PWA_ANNOTATION);
throw new IllegalStateException(ERROR_INVALID_PWA_ANNOTATION
+ " " + hopefullyAppShellClass.getName()
+ " does not implement "
+ AppShellConfigurator.class.getSimpleName());
}

Annotation pwa = annotationFinder
Expand Down

0 comments on commit 2c4c9fc

Please sign in to comment.