YAML parser: filter unexpected part from the parse exception message (#4759)

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
lolodomo
2025-04-30 22:11:16 +02:00
committed by GitHub
parent 003c6e18e1
commit 3404384c47
@@ -91,6 +91,8 @@ public class YamlModelRepositoryImpl implements WatchService.WatchEventListener,
getElementName(YamlThingDTO.class) // "things"
);
private static final String UNWANTED_EXCEPTION_TEXT = "at [Source: UNKNOWN; byte offset: #UNKNOWN] ";
private final Logger logger = LoggerFactory.getLogger(YamlModelRepositoryImpl.class);
private final WatchService watchService;
@@ -709,8 +711,9 @@ public class YamlModelRepositoryImpl implements WatchService.WatchEventListener,
return Optional.of(objectMapper.treeToValue(node, elementClass));
} catch (JsonProcessingException e) {
if (errors != null) {
String msg = e.getMessage();
errors.add("Could not parse element %s to %s: %s".formatted(node.toPrettyString(),
elementClass.getSimpleName(), e.getMessage()));
elementClass.getSimpleName(), msg == null ? "" : msg.replace(UNWANTED_EXCEPTION_TEXT, "")));
}
return Optional.empty();
}
@@ -743,8 +746,10 @@ public class YamlModelRepositoryImpl implements WatchService.WatchEventListener,
elt.setId(id);
} catch (JsonProcessingException e) {
if (errors != null) {
String msg = e.getMessage();
errors.add("could not parse element %s to %s: %s".formatted(node.toPrettyString(),
elementClass.getSimpleName(), e.getMessage()));
elementClass.getSimpleName(),
msg == null ? "" : msg.replace(UNWANTED_EXCEPTION_TEXT, "")));
}
}
}