Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/05/10 17:26:13 (14 years ago)
Author:
swagner
Message:

Improved error messages of ConfigMerger (#827)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/ConfigMerger/ConfigMerger.cs

    r1142 r2602  
    3333      }
    3434      catch (Exception ex) {
    35         Console.Out.WriteLine(ex.Message);
     35        Console.Out.WriteLine(BuildErrorMessage(ex));
    3636      }
    3737    }
     
    8686
    8787    private static void Merge(XmlNode source, XmlNode destination, XmlDocument document, string root) {
    88       if (source != null) {
    89         if (destination == null) {
    90           XmlNode newNode = document.ImportNode(source, true);
    91           document.SelectSingleNode(root).AppendChild(newNode);
    92         } else {
    93           foreach (XmlNode node in source.ChildNodes) {
    94             XmlNode newNode = document.ImportNode(node, true);
    95             XmlNode oldNode = destination.SelectSingleNode(BuildXPathString(newNode));
    96             if (oldNode != null)
    97               destination.ReplaceChild(newNode, oldNode);
    98             else
    99               destination.AppendChild(newNode);
     88      try {
     89        if (source != null) {
     90          if (destination == null) {
     91            XmlNode newNode = document.ImportNode(source, true);
     92            document.SelectSingleNode(root).AppendChild(newNode);
     93          } else {
     94            foreach (XmlNode node in source.ChildNodes) {
     95              XmlNode newNode = document.ImportNode(node, true);
     96              XmlNode oldNode = destination.SelectSingleNode(BuildXPathString(newNode));
     97              if (oldNode != null)
     98                destination.ReplaceChild(newNode, oldNode);
     99              else
     100                destination.AppendChild(newNode);
     101            }
    100102          }
    101103        }
     104      }
     105      catch (Exception ex) {
     106        StringBuilder sb = new StringBuilder();
     107        sb.Append("Error while merging node \"").Append(source.Name).Append("\"");
     108        throw new Exception(sb.ToString(), ex);
    102109      }
    103110    }
     
    118125      return builder.ToString();
    119126    }
     127
     128    private static string BuildErrorMessage(Exception ex) {
     129      StringBuilder sb = new StringBuilder();
     130      sb.Append("\n\n");
     131      sb.Append("### ConfigMerger ERROR ###########################################\n" + ex.Message + "\n" + ex.StackTrace + "\n");
     132      while (ex.InnerException != null) {
     133        ex = ex.InnerException;
     134        sb.Append("-----\n" + ex.Message + "\n" + ex.StackTrace + "\n");
     135      }
     136      sb.Append("##################################################################\n\n");
     137      return sb.ToString();
     138    }
    120139  }
    121140}
Note: See TracChangeset for help on using the changeset viewer.