Skip to content

Commit 1b3fe81

Browse files
christophstroblmp911de
authored andcommitted
DATAREDIS-482 - Provide meaningful exception messages in MappingRedisConverter.
Original pull request: spring-projects#183.
1 parent b3243ff commit 1b3fe81

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/main/java/org/springframework/data/redis/core/convert/MappingRedisConverter.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ private void writeToBucket(String path, Object value, RedisData sink) {
509509
}
510510

511511
if (customConversions.hasCustomWriteTarget(value.getClass())) {
512+
512513
Class<?> targetType = customConversions.getCustomWriteTarget(value.getClass());
513514

514515
if (ClassUtils.isAssignable(Map.class, targetType)) {
@@ -521,9 +522,9 @@ private void writeToBucket(String path, Object value, RedisData sink) {
521522
} else if (ClassUtils.isAssignable(byte[].class, targetType)) {
522523
sink.getBucket().put(path, toBytes(value));
523524
} else {
524-
throw new IllegalArgumentException("converter must not fool me!!");
525+
throw new IllegalArgumentException(
526+
String.format("Cannot convert value '%s' of type %s to bytes.", value, value.getClass()));
525527
}
526-
527528
}
528529

529530
}
@@ -634,7 +635,8 @@ private void writeMap(String keyspace, String path, Class<?> mapValueType, Map<?
634635

635636
Matcher matcher = pattern.matcher(entry.getKey());
636637
if (!matcher.find()) {
637-
throw new RuntimeException("baähhh");
638+
throw new IllegalArgumentException(
639+
String.format("Cannot extract map value for key '%s' in path '%s'.", entry.getKey(), path));
638640
}
639641
String key = matcher.group(2);
640642
target.put(key, fromBytes(entry.getValue(), valueType));
@@ -665,7 +667,8 @@ private void writeMap(String keyspace, String path, Class<?> mapValueType, Map<?
665667

666668
Matcher matcher = pattern.matcher(key);
667669
if (!matcher.find()) {
668-
throw new RuntimeException("baähhh");
670+
throw new IllegalArgumentException(
671+
String.format("Cannot extract map value for key '%s' in path '%s'.", key, path));
669672
}
670673
String mapKey = matcher.group(2);
671674

0 commit comments

Comments
 (0)