Improve error logs.

- Include root cause exception.
- Add info what failed.

Change-Id: Id3ea1ca514cae6884a67174606b0e84ed458aec5
diff --git a/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangLinkerManager.java b/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangLinkerManager.java
index dacc201..a22bbd0 100644
--- a/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangLinkerManager.java
+++ b/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangLinkerManager.java
@@ -120,7 +120,7 @@
                         "line: " + e.getLineNumber() + " at position: " +
                         e.getCharPositionInLine() + NEW_LINE +
                         e.getLocalizedMessage();
-                throw new LinkerException(errorInfo);
+                throw new LinkerException(errorInfo, e);
                 // TODO add file path in exception message in util manager.
             } catch (LinkerException e) {
                 String errorInfo = "Error in file: " + yangNode.getName() +
@@ -128,7 +128,7 @@
                         "line: " + e.getLineNumber() + " at position: " +
                         e.getCharPositionInLine() + NEW_LINE +
                         e.getLocalizedMessage();
-                throw new LinkerException(errorInfo);
+                throw new LinkerException(errorInfo, e);
                 // TODO add file path in exception message in util manager.
             }
         }
@@ -151,7 +151,7 @@
                             yangNode.getFileName() + " at " +
                             "line: " + e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE
                             + e.getLocalizedMessage();
-                    throw new LinkerException(errorInfo);
+                    throw new LinkerException(errorInfo, e);
                     // TODO add file path in exception message in util manager.
                 }
             }
@@ -175,7 +175,7 @@
                             yangNode.getFileName() + " at " +
                             "line: " + e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE
                             + e.getLocalizedMessage();
-                    throw new LinkerException(errorInfo);
+                    throw new LinkerException(errorInfo, e);
                     // TODO add file path in exception message in util manager.
                 }
             }
@@ -199,7 +199,7 @@
                             yangNode.getFileName() + " at " +
                             "line: " + e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE
                             + e.getLocalizedMessage();
-                    throw new LinkerException(errorInfo);
+                    throw new LinkerException(errorInfo, e);
                     // TODO add file path in exception message in util manager.
                 }
             }
@@ -236,14 +236,14 @@
                         yangNode.getFileName() + " at " +
                         "line: " + e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE
                         + e.getLocalizedMessage();
-                throw new LinkerException(errorInfo);
+                throw new LinkerException(errorInfo, e);
                 // TODO add file path in exception message in util manager.
             } catch (LinkerException e) {
                 String errorInfo = "Error in file: " + yangNode.getName() + " in " +
                         yangNode.getFileName() + " at " +
                         "line: " + e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE
                         + e.getLocalizedMessage();
-                throw new LinkerException(errorInfo);
+                throw new LinkerException(errorInfo, e);
                 // TODO add file path in exception message in util manager.
             }
         }
@@ -271,7 +271,7 @@
                         "line: " + e.getLineNumber() + " at position: " +
                         e.getCharPositionInLine() + NEW_LINE +
                         e.getLocalizedMessage();
-                throw new LinkerException(errorInfo);
+                throw new LinkerException(errorInfo, e);
                 // TODO add file path in exception message in util manager.
             } catch (LinkerException e) {
                 String errorInfo = "Error in file: " + yangNode.getName() +
@@ -279,7 +279,7 @@
                         "line: " + e.getLineNumber() + " at position: " +
                         e.getCharPositionInLine() + NEW_LINE +
                         e.getLocalizedMessage();
-                throw new LinkerException(errorInfo);
+                throw new LinkerException(errorInfo, e);
                 // TODO add file path in exception message in util manager.
             }
         }
diff --git a/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangLinkerUtils.java b/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangLinkerUtils.java
index e246f07..86fca1e 100644
--- a/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangLinkerUtils.java
+++ b/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangLinkerUtils.java
@@ -713,7 +713,7 @@
                                             " at position: " + e.getCharPositionInLine()
                                             + e.getLocalizedMessage();
                                     throw new LinkerException("Failed to add type info in grouping to resolution "
-                                                                      + errorInfo);
+                                                                      + errorInfo, e);
                                 }
                             }
                         }
@@ -754,7 +754,7 @@
                     try {
                         addResolutionInfo(resolutionInfo);
                     } catch (DataModelException e) {
-                        throw new LinkerException("Failed to add leaf type info in grouping, to resolution ");
+                        throw new LinkerException("Failed to add leaf type info in grouping, to resolution ", e);
                     }
                 } else if (type.getDataType() == IDENTITYREF) {
                     YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo();
@@ -763,13 +763,14 @@
 
                     // Add resolution information to the list
                     YangResolutionInfoImpl resolutionInfo =
-                            new YangResolutionInfoImpl<YangIdentityRef>(identityRef, (YangNode) leavesHolder,
+                            new YangResolutionInfoImpl<>(identityRef, (YangNode) leavesHolder,
                                                                         identityRef.getLineNumber(),
                                                                         identityRef.getCharPosition());
                     try {
                         addResolutionInfo(resolutionInfo);
                     } catch (DataModelException e) {
-                        throw new LinkerException("Failed to add leaf identity ref info in grouping, to resolution ");
+                        throw new LinkerException("Failed to add leaf identity ref info in grouping, to resolution ",
+                                                  e);
                     }
                 }
             }
@@ -784,7 +785,7 @@
 
                     // Add resolution information to the list
                     YangResolutionInfoImpl resolutionInfo =
-                            new YangResolutionInfoImpl<YangType>(type, (YangNode) leavesHolder,
+                            new YangResolutionInfoImpl<>(type, (YangNode) leavesHolder,
                                                                  type.getLineNumber(), type.getCharPosition());
                     try {
                         addResolutionInfo(resolutionInfo);
@@ -797,7 +798,7 @@
                     identityRef.setIdentityForInterFileGroupingResolution(true);
                     // Add resolution information to the list
                     YangResolutionInfoImpl resolutionInfo =
-                            new YangResolutionInfoImpl<YangIdentityRef>(identityRef, (YangNode) leavesHolder,
+                            new YangResolutionInfoImpl<>(identityRef, (YangNode) leavesHolder,
                                                                         identityRef.getLineNumber(),
                                                                         identityRef.getCharPosition());
                     try {
diff --git a/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangXpathLinker.java b/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangXpathLinker.java
index d06e3e6..5352a8e 100644
--- a/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangXpathLinker.java
+++ b/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangXpathLinker.java
@@ -438,7 +438,7 @@
         try {
             id = id.substring(ind + 1, id.length() - 1);
         } catch (StringIndexOutOfBoundsException e) {
-            throw new LinkerException("Invalid augment path");
+            throw new LinkerException("Invalid augment path: " + id);
         }
         StringBuilder str = new StringBuilder();
         String[] arr;
diff --git a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/ModuleListener.java b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/ModuleListener.java
index b182e12..67b5a36 100644
--- a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/ModuleListener.java
+++ b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/ModuleListener.java
@@ -144,7 +144,7 @@
             resolver.resolveSelfFileLinking(YANG_BASE);
             resolver.resolveSelfFileLinking(YANG_IDENTITYREF);
         } catch (DataModelException e) {
-            LinkerException linkerException = new LinkerException(e.getMessage());
+            LinkerException linkerException = new LinkerException(e.getMessage(), e);
             linkerException.setLine(e.getLineNumber());
             linkerException.setCharPosition(e.getCharPositionInLine());
             linkerException.setFileName(listener.getFileName());
diff --git a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/SubModuleListener.java b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/SubModuleListener.java
index cc45272..5ee9b26 100644
--- a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/SubModuleListener.java
+++ b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/SubModuleListener.java
@@ -145,7 +145,7 @@
             ((YangReferenceResolver) listener.getParsedDataStack().peek())
                     .resolveSelfFileLinking(ResolvableType.YANG_IDENTITYREF);
         } catch (DataModelException e) {
-            LinkerException linkerException = new LinkerException(e.getMessage());
+            LinkerException linkerException = new LinkerException(e.getMessage(), e);
             linkerException.setLine(e.getLineNumber());
             linkerException.setCharPosition(e.getCharPositionInLine());
             linkerException.setFileName(listener.getFileName());
diff --git a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/YangCompilerManager.java b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/YangCompilerManager.java
index b8eaf6e..1a67b1e 100644
--- a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/YangCompilerManager.java
+++ b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/YangCompilerManager.java
@@ -224,7 +224,7 @@
             } catch (IOException e) {
                 throw new YangCompilerException(
                         "Failed to fetch dependent schema from given " +
-                                "path :" + path.toString());
+                                "path :" + path.toString(), e);
             }
         }
         return depNodes;
@@ -262,7 +262,7 @@
         } catch (LinkerException e) {
             printLog(e.getFileName(), e.getLineNumber(), e.getCharPositionInLine(),
                      e.getMessage(), e.getLocalizedMessage());
-            throw new YangCompilerException(e.getMessage());
+            throw new YangCompilerException(e.getMessage(), e);
         }
     }
 
@@ -391,7 +391,7 @@
             boolean isCreated = targetDir.mkdirs();
             if (!isCreated) {
                 throw new YangCompilerException(
-                        "failed to create yang resource directory.");
+                        "failed to create yang resource directory: " + path);
             }
         }
 
diff --git a/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangGenerator.java b/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangGenerator.java
index 18f4133..30f9bd0 100644
--- a/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangGenerator.java
+++ b/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangGenerator.java
@@ -80,7 +80,7 @@
                     }
                 } catch (IOException e) {
                     throw new YangCompilerException(
-                            "Failed to parse dependent schema path");
+                            "Failed to parse dependent schema path", e);
                 }
             }
             bldr.setCodeGenDir(Paths.get(outputDirectory));