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
…19927)

Co-authored-by: Marco Collovati <[email protected]>
  • Loading branch information
vaadin-bot and mcollovati authored Sep 10, 2024
1 parent cb910e1 commit 4a4f695
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 @@ -706,14 +706,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 @@ -496,15 +496,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 4a4f695

Please sign in to comment.