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

KB - Adds a check which makes sure that the template is rendering before... #1891

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/main/java/sirius/biz/tycho/kb/SynchronizeArticlesTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ private void updateArticle(String templatePath, String syncId) {
.orElseThrow(() -> new IllegalArgumentException("Failed to load KBA: "
+ templatePath));
GlobalRenderContext context = tagliatelle.createRenderContext();
template.render(context);

if (!tryRender(template, context)) {
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sollte man das net irgendwie loggen/sich merken?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ne, nur abbrechen wenn es false zurück gibt und dementsprechend nicht gerendert werden kann

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ich sehe, dass der Code das macht. 😇 Ich möchte wissen, ob das reicht. Bekommen wir ein fehlerhaftes Template anderweitig mit? Haben wir eine Chance, das zu entdecken? Oder sind wir darauf angewiesen, dass irgendwer irgendwann merkt, dass ein Artikel fehlt?

Copy link
Member

@sabieber sabieber Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guter Punkt finde ich. Vielleicht sollten wir KBA Komponenten doch in n anderes Verzeichnis legen oder anderweitig markieren, statt den Mechanismus zu verbiegen

}

if (!isArticle(context)) {
return;
Expand Down Expand Up @@ -153,6 +156,15 @@ private void updateArticle(String templatePath, String syncId) {
}
}

private boolean tryRender(Template template, GlobalRenderContext context) {
try {
template.render(context);
return true;
} catch (Exception ignored) {
return false;
}
}

private boolean isArticle(GlobalRenderContext context) {
String articleId = context.getExtraBlock(BLOCK_CODE);
String language = context.getExtraBlock(BLOCK_LANG);
Expand Down