Skip to content

Commit

Permalink
add field name to an exception
Browse files Browse the repository at this point in the history
When a field is not set, i'd be nice to know what field it is - currently we are seeing just `Value cannot be null` and we start the scavenger hunt to find out what the field is. 
Would be good to show field names for ever missing (null) field
  • Loading branch information
Toli Kuznets committed Apr 4, 2018
1 parent 4d001ed commit bf7040b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions morphia/src/main/java/org/mongodb/morphia/query/UpdateOpsImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public UpdateOperations<T> removeLast(final String field) {
@Override
public UpdateOperations<T> set(final String field, final Object value) {
if (value == null) {
throw new QueryException("Value cannot be null.");
throw new QueryException("Value for field ["+field+"] cannot be null.");
}

add(UpdateOperator.SET, field, value, true);
Expand All @@ -227,7 +227,20 @@ public UpdateOperations<T> set(final String field, final Object value) {
@Override
public UpdateOperations<T> setOnInsert(final String field, final Object value) {
if (value == null) {
throw new QueryException("Value cannot be null.");
throw new QueryException("
t be null.");
}

add(UpdateOperator.SET_ON_INSERT, field, value, true);
Expand Down

0 comments on commit bf7040b

Please sign in to comment.