Improve exception message

- add information abbout failed value
- do now swallow original exception

Change-Id: Ia15757451b182581244bcf6014a2bf6bfcf4591d
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangType.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangType.java
index b9dcc42..9238f7f 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangType.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangType.java
@@ -25,6 +25,8 @@
 import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes;
 import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangUint64;
 
+import com.google.common.base.MoreObjects;
+
 import java.io.Serializable;
 import java.math.BigInteger;
 import java.util.Iterator;
@@ -397,7 +399,7 @@
                         .listIterator();
                 boolean isValidated = false;
                 while (listIterator.hasNext()) {
-                    YangType<?> type = (YangType<?>) listIterator.next();
+                    YangType<?> type = listIterator.next();
                     try {
                         type.isValidValue(value);
                         // If it is not thrown exception then validation is success
@@ -462,7 +464,7 @@
                     }
                 } else if (dataType == YangDataTypes.DECIMAL64) {
                     YangDerivedInfo derivedInfo = (YangDerivedInfo) getDataTypeExtendedInfo();
-                    YangTypeDef typedef = (YangTypeDef) derivedInfo.getReferredTypeDef();
+                    YangTypeDef typedef = derivedInfo.getReferredTypeDef();
                     YangType<YangDecimal64> decimal64Type =
                             (YangType<YangDecimal64>) typedef.getTypeList().iterator().next();
                     YangDecimal64<YangRangeRestriction> decimal64 = decimal64Type.getDataTypeExtendedInfo();
@@ -556,4 +558,17 @@
         YangType<T> clonedNode = (YangType<T>) super.clone();
         return clonedNode;
     }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this)
+                .omitNullValues()
+                .add("nodeId", nodeId)
+                .add("dataType", dataType)
+                .add("dataTypeExtendedInfo", dataTypeExtendedInfo)
+                .add("resolvableStatus", resolvableStatus)
+                .add("isTypeForInterFileGroupingResolution", isTypeForInterFileGroupingResolution)
+                .add("isTypeNotResolvedTillRootNode", isTypeNotResolvedTillRootNode)
+                .toString();
+    }
 }
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/LeafContextUtil.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/LeafContextUtil.java
index 6e7d008..22aa13a 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/LeafContextUtil.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/LeafContextUtil.java
@@ -100,7 +100,7 @@
                 if (v.equals(T) || v.equals(F)) {
                     return Boolean.parseBoolean(v);
                 }
-                throw new IllegalArgumentException(E_DATATYPE);
+                throw new IllegalArgumentException("Invalid boolean value: " + v);
             case ENUMERATION:
                 try {
                     SortedSet<YangEnum> set = ((YangEnumeration) typeInfo
@@ -113,7 +113,7 @@
                 } catch (Exception e) {
                     // do nothing
                 }
-                throw new IllegalArgumentException(E_DATATYPE);
+                throw new IllegalArgumentException("Invalid " + typeInfo + " value: " + v);
             case BITS:
                 try {
                     YangBits e = ((YangBits) typeInfo
@@ -126,12 +126,12 @@
                 } catch (Exception e) {
                     // do nothing
                 }
-                throw new IllegalArgumentException(E_DATATYPE);
+                throw new IllegalArgumentException("Invalid " + typeInfo + " value: " + v);
             case BINARY:
                 if (v.matches(BREGEX)) {
                     return v;
                 }
-                throw new IllegalArgumentException(E_DATATYPE);
+                throw new IllegalArgumentException("Invalid " + typeInfo + " value: " + v);
             case IDENTITYREF:
             case STRING:
             case INSTANCE_IDENTIFIER:
@@ -151,7 +151,7 @@
             case UNION:
                 return parseUnionTypeInfo(typeInfo, v);
             default:
-                throw new IllegalArgumentException(E_DATATYPE);
+                throw new IllegalArgumentException("Unexpected data type " + type);
         }
     }
 
@@ -208,7 +208,7 @@
             case UNION:
                 return getUnionValNamespace(typeInfo, v);
             default:
-                throw new IllegalArgumentException(E_DATATYPE);
+                throw new IllegalArgumentException("Unexpected data type " + type);
         }
     }
 
@@ -223,7 +223,7 @@
                 return i.getYangSchemaNodeIdentifier().getNameSpace();
             }
         }
-        throw new IllegalArgumentException("Invalid value of data");
+        throw new IllegalArgumentException("Invalid value of data: " + v);
     }
 
     private static YangNamespace getUnionValNamespace(YangType type,
@@ -239,7 +239,7 @@
                 continue;
             }
         }
-        throw new IllegalArgumentException("Invalid value of data");
+        throw new IllegalArgumentException("Invalid value of data: " + leafValue);
     }
 
     /**
@@ -260,7 +260,7 @@
                 continue;
             }
         }
-        throw new IllegalArgumentException("Invalid value of data");
+        throw new IllegalArgumentException("Invalid value of data: " + leafValue);
     }
 
     /**
@@ -302,12 +302,12 @@
                 if (v == null || v.equals("") || (v.equals(T) || v.equals(F))) {
                     return LeafType.EMPTY;
                 }
-                throw new IllegalArgumentException(E_DATATYPE);
+                throw new IllegalArgumentException("Invalid empty value: " + v);
             case BOOLEAN:
                 if (v.equals(T) || v.equals(F)) {
                     return LeafType.BOOLEAN;
                 }
-                throw new IllegalArgumentException(E_DATATYPE);
+                throw new IllegalArgumentException("Invalid boolean value: " + v);
             case BINARY:
                 return LeafType.BINARY;
             case BITS:
@@ -335,7 +335,7 @@
             case UNION:
                 return parseUnionLeafType(typeInfo, v);
             default:
-                throw new IllegalArgumentException(E_DATATYPE);
+                throw new IllegalArgumentException("Unexpected data type " + type);
         }
     }
 
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/SerializerHelper.java b/runtime/src/main/java/org/onosproject/yang/runtime/SerializerHelper.java
index 7fae4ce..2a48d90 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/SerializerHelper.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/SerializerHelper.java
@@ -124,7 +124,7 @@
                 builder.appInfo(parentCont);
             }
         } catch (IllegalArgumentException e) {
-            throw new IllegalArgumentException(e.getMessage());
+            throw e;
         }
         return builder;
     }
@@ -178,7 +178,7 @@
                     try {
                         checkElementCount(name, keyLeafs.size(), value.size());
                     } catch (IllegalArgumentException e) {
-                        throw new IllegalArgumentException(e.getMessage());
+                        throw e;
                     }
 
                     // After validation adding the key nodes under the list node.
@@ -201,7 +201,7 @@
                         errorMsg(FMT_NOT_EXIST, name));
             }
         } catch (IllegalArgumentException e) {
-            throw new IllegalArgumentException(e.getMessage());
+            throw e;
         }
 
         builder.appInfo(child);
@@ -425,7 +425,7 @@
             nodeInfo.setResourceIdBuilder(rIdBldr);
             builder.appInfo(nodeInfo);
         } catch (IllegalArgumentException e) {
-            throw new IllegalArgumentException(e.getMessage());
+            throw e;
         }
         return builder;
     }
@@ -444,7 +444,7 @@
         try {
             ((YangLeafList) ctx).getDataType().isValidValue(val);
         } catch (DataModelException e) {
-            throw new IllegalArgumentException(e.getMessage());
+            throw new IllegalArgumentException(e);
         }
         return ctx.fromString(val);
     }
@@ -462,7 +462,7 @@
         try {
             ((YangLeaf) ctx).getDataType().isValidValue(val);
         } catch (DataModelException e) {
-            throw new IllegalArgumentException(e.getMessage());
+            throw new IllegalArgumentException(e);
         }
         return ctx.fromString(val);
     }