Skip to content

Commit

Permalink
Merge pull request #10216 from mkouba/issue-10209
Browse files Browse the repository at this point in the history
Qute - result mappers may throw an exception
  • Loading branch information
gsmet authored Jun 24, 2020
2 parents 93e1d0f + fb7f872 commit 915da86
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static CompletionStage<Map<String, Object>> evaluateParams(Map<String, Expressio
paramValues.put(entry.getKey(), results[j++].get());
}
result.complete(paramValues);
} catch (Exception e) {
} catch (Throwable e) {
result.completeExceptionally(e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ CompletionStage<Object> evaluateNext(SectionResolutionContext context, Object va
localValue = null;
}
val = operator.evaluate(localValue, r);
} catch (Exception e) {
} catch (Throwable e) {
result.completeExceptionally(e);
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,12 @@ private CompletionStage<Void> renderData(Object data, Consumer<String> consumer)
result.completeExceptionally(t);
} else {
// Sync processing of the result tree - build the output
r.process(consumer);
result.complete(null);
try {
r.process(consumer);
result.complete(null);
} catch (Throwable e) {
result.completeExceptionally(e);
}
}
});
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public CompletionStage<ResultNode> resolve(SectionResolutionContext context) {
result.complete(r2);
}
});
} catch (Exception e) {
} catch (Throwable e) {
result.completeExceptionally(e);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.qute;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import io.quarkus.qute.Results.Result;
import io.quarkus.qute.TemplateNode.Origin;
Expand Down Expand Up @@ -161,10 +162,6 @@ public String map(Object result, Expression expression) {
}
}).addResultMapper(new ResultMapper() {

public int getPriority() {
return 1;
}

public boolean appliesTo(Origin origin, Object val) {
return val.equals(Result.NOT_FOUND);
}
Expand All @@ -175,10 +172,6 @@ public String map(Object result, Expression expression) {
}
}).addResultMapper(new ResultMapper() {

public int getPriority() {
return 1;
}

public boolean appliesTo(Origin origin, Object val) {
return val instanceof Collection;
}
Expand All @@ -193,4 +186,26 @@ public String map(Object result, Expression expression) {
.render(Collections.emptyList()));
}

@Test
public void testNotFoundThrowException() {
try {
Engine.builder().addDefaults()
.addResultMapper(new ResultMapper() {

public boolean appliesTo(Origin origin, Object val) {
return val.equals(Result.NOT_FOUND);
}

@Override
public String map(Object result, Expression expression) {
throw new IllegalStateException("Not found: " + expression.toOriginalString());
}
}).build()
.parse("{foo}")
.render();
fail();
} catch (IllegalStateException expected) {
assertEquals("Not found: foo", expected.getMessage());
}
}
}

0 comments on commit 915da86

Please sign in to comment.