From 6399d0ad470a83fe91377ef17695e8fb4bcba2bc Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Thu, 13 Jun 2024 11:36:48 +0100 Subject: [PATCH] Improve message on mapping generation failure (#1175) --- .../main/java/io/smallrye/config/ConfigMappingContext.java | 1 - .../java/io/smallrye/config/ConfigMappingInterface.java | 6 +++++- .../java/io/smallrye/config/_private/ConfigMessages.java | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/implementation/src/main/java/io/smallrye/config/ConfigMappingContext.java b/implementation/src/main/java/io/smallrye/config/ConfigMappingContext.java index ac62cefe2..2f6818b39 100644 --- a/implementation/src/main/java/io/smallrye/config/ConfigMappingContext.java +++ b/implementation/src/main/java/io/smallrye/config/ConfigMappingContext.java @@ -148,7 +148,6 @@ public StringBuilder getNameBuilder() { @SuppressWarnings("unused") public void reportProblem(RuntimeException problem) { - problem.printStackTrace(); problems.add(new Problem(problem.toString())); } diff --git a/implementation/src/main/java/io/smallrye/config/ConfigMappingInterface.java b/implementation/src/main/java/io/smallrye/config/ConfigMappingInterface.java index 5547eb479..8704ebc35 100644 --- a/implementation/src/main/java/io/smallrye/config/ConfigMappingInterface.java +++ b/implementation/src/main/java/io/smallrye/config/ConfigMappingInterface.java @@ -167,7 +167,11 @@ List getNested() { } public byte[] getClassBytes() { - return ConfigMappingGenerator.generate(this); + try { + return ConfigMappingGenerator.generate(this); + } catch (Throwable e) { + throw ConfigMessages.msg.couldNotGenerateMapping(e); + } } public static abstract class Property { diff --git a/implementation/src/main/java/io/smallrye/config/_private/ConfigMessages.java b/implementation/src/main/java/io/smallrye/config/_private/ConfigMessages.java index 51a24aa72..97b4084a8 100644 --- a/implementation/src/main/java/io/smallrye/config/_private/ConfigMessages.java +++ b/implementation/src/main/java/io/smallrye/config/_private/ConfigMessages.java @@ -169,4 +169,7 @@ IllegalArgumentException converterException(@Cause Throwable converterException, @Message(id = 50, value = "%s in %s does not map to any root") IllegalStateException propertyDoesNotMapToAnyRoot(String name, String location); + + @Message(id = 51, value = "Could not generate ConfigMapping") + IllegalStateException couldNotGenerateMapping(@Cause Throwable throwable); }