Skip to content

Commit

Permalink
Qute parser - improve error messages
Browse files Browse the repository at this point in the history
- resolves #6164
  • Loading branch information
mkouba committed Jan 8, 2020
1 parent 3fa3c72 commit 22bd4ae
Show file tree
Hide file tree
Showing 13 changed files with 212 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.lang.reflect.Modifier;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand Down Expand Up @@ -71,7 +73,10 @@
import io.quarkus.qute.SectionHelper;
import io.quarkus.qute.SectionHelperFactory;
import io.quarkus.qute.Template;
import io.quarkus.qute.TemplateException;
import io.quarkus.qute.TemplateInstance;
import io.quarkus.qute.TemplateLocator;
import io.quarkus.qute.Variant;
import io.quarkus.qute.api.ResourcePath;
import io.quarkus.qute.api.VariantTemplate;
import io.quarkus.qute.deployment.TemplatesAnalysisBuildItem.TemplateAnalysis;
Expand Down Expand Up @@ -163,15 +168,37 @@ public CompletionStage<ResultNode> resolve(SectionResolutionContext context) {
};
}
};
}).addLocator(new TemplateLocator() {
@Override
public Optional<TemplateLocation> locate(String id) {
TemplatePathBuildItem found = templatePaths.stream().filter(p -> p.getPath().equals(id)).findAny().orElse(null);
if (found != null) {
try {
byte[] content = Files.readAllBytes(found.getFullPath());
return Optional.of(new TemplateLocation() {
@Override
public Reader read() {
return new StringReader(new String(content, StandardCharsets.UTF_8));
}

@Override
public Optional<Variant> getVariant() {
return Optional.empty();
}
});
} catch (IOException e) {
LOGGER.warn("Unable to read the template from path: " + found.getFullPath(), e);
}
}
;
return Optional.empty();
}
}).build();

for (TemplatePathBuildItem path : templatePaths) {
try {
Template template = dummyEngine
.parse(new String(Files.readAllBytes(path.getFullPath()), StandardCharsets.UTF_8));
Template template = dummyEngine.getTemplate(path.getPath());
if (template != null) {
analysis.add(new TemplateAnalysis(template.getGeneratedId(), template.getExpressions(), path));
} catch (IOException e) {
LOGGER.warn("Unable to analyze the template from path: " + path.getFullPath(), e);
}
}
LOGGER.debugf("Finished analysis of %s templates in %s ms",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.qute.TemplateException;
import io.quarkus.test.QuarkusUnitTest;

public class NamedBeanNotFoundTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.qute.TemplateException;
import io.quarkus.test.QuarkusUnitTest;

public class NamedBeanPropertyNotFoundTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.qute.TemplateException;
import io.quarkus.test.QuarkusUnitTest;

public class PropertyNotFoundTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.qute.TemplateException;
import io.quarkus.test.QuarkusUnitTest;

public class TypeSafeLoopFailureTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class EngineImpl implements Engine {

@Override
public Template parse(String content, Variant variant) {
return new Parser(this).parse(new StringReader(content), Optional.ofNullable(variant));
String generatedId = generateId();
return new Parser(this).parse(new StringReader(content), Optional.ofNullable(variant), generatedId, generatedId);
}

@Override
Expand Down Expand Up @@ -131,7 +132,7 @@ private Template load(String id) {
Optional<TemplateLocation> location = locator.locate(id);
if (location.isPresent()) {
try (Reader r = location.get().read()) {
return new Parser(this).parse(ensureBufferedReader(r), location.get().getVariant());
return new Parser(this).parse(ensureBufferedReader(r), location.get().getVariant(), id, generateId());
} catch (IOException e) {
LOGGER.warn("Unable to close the reader for " + id, e);
}
Expand Down
Loading

0 comments on commit 22bd4ae

Please sign in to comment.