Skip to content

Commit 77f83e5

Browse files
committed
Specify failed to process property
1 parent 1c9f0d6 commit 77f83e5

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

core/src/main/java/net/roxymc/jserialize/creator/InstanceCreator.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public T createInstance() throws Throwable {
3232
ConstructorModel constructor = classModel.constructor();
3333

3434
if (constructor == null) {
35-
throw new IllegalStateException("No constructor found");
35+
throw new IllegalStateException("No constructor found for " + classModel.clazz());
3636
}
3737

3838
ParameterModel[] parameters = constructor.parameters();
@@ -48,8 +48,8 @@ public T createInstance() throws Throwable {
4848
continue;
4949
}
5050

51-
// parent should be passed here
52-
Object resolvedValue = value.get(null);
51+
// TODO parent should be passed here
52+
Object resolvedValue = value.getSafe(name, null);
5353
validateValue(name, resolvedValue, meta);
5454

5555
values[parameter.index()] = resolvedValue;
@@ -97,7 +97,7 @@ private T populate(T instance, boolean skipParams) throws Throwable {
9797
}
9898

9999
if (!canMutate) {
100-
Object resolvedValue = value.get(instance);
100+
Object resolvedValue = value.getSafe(name, instance);
101101
validateValue(name, resolvedValue, meta);
102102

103103
property.setter().set(instance, resolvedValue);
@@ -108,12 +108,12 @@ private T populate(T instance, boolean skipParams) throws Throwable {
108108

109109
if (value instanceof PropertyValue.Mutable) {
110110
//noinspection unchecked,rawtypes
111-
((PropertyValue.Mutable) value).mutate(instance, currentValue);
111+
((PropertyValue.Mutable) value).mutateSafe(name, instance, currentValue);
112112
continue;
113113
}
114114

115115
if (currentValue instanceof Collection || currentValue instanceof Map) {
116-
Object resolvedValue = value.get(instance);
116+
Object resolvedValue = value.getSafe(name, instance);
117117
if (resolvedValue == null) {
118118
validateValue(name, null, meta);
119119
continue;

core/src/main/java/net/roxymc/jserialize/creator/PropertyValue.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ static <T> PropertyValue<T> of(@Nullable T value) {
1212

1313
@Nullable T get(@Nullable Object parent) throws Throwable;
1414

15+
default @Nullable T getSafe(String name, @Nullable Object parent) {
16+
try {
17+
return get(parent);
18+
} catch (Throwable ex) {
19+
throw new RuntimeException("Failed to process property: " + name, ex);
20+
}
21+
}
22+
1523
@FunctionalInterface
1624
interface Mutable<T> extends PropertyValue<T> {
1725
Mutable<?> NOOP = (parent, instance) -> instance;
@@ -22,5 +30,13 @@ interface Mutable<T> extends PropertyValue<T> {
2230
}
2331

2432
@Nullable T mutate(@Nullable Object parent, @Nullable T instance) throws Throwable;
33+
34+
default @Nullable T mutateSafe(String name, @Nullable Object parent, @Nullable T instance) {
35+
try {
36+
return mutate(parent, instance);
37+
} catch (Throwable ex) {
38+
throw new RuntimeException("Failed to process property: " + name, ex);
39+
}
40+
}
2541
}
2642
}

0 commit comments

Comments
 (0)