[wpkg-users] Misleading "Error parsing xml" in log file. Proposed patch

Mi mi.lists.wpkg at alma.ch
Thu Feb 23 21:39:47 CET 2012


Under some circumstances, wpkg.js tries to parse non-existing .xml files, and writes an "ERROR" into the log file. This is misleading in situations where it is normal that the file does not exist.

For example, when using a "packages" directory of .xml files instead of a single packages.xml file, wpkg.js still tries to parse the non-existing packages.xml.

I have a cron job parsing the log files for "ERROR"s, and now it prints these for every reboot of every machine, because the log contains:

2012-02-23 15:13:33, DEBUG : Reading XML file: //192.168.44.1/install/wpkg/packages/twixtel.xml
2012-02-23 15:13:33, DEBUG : Reading XML file: //192.168.44.1/install/wpkg/packages/user-settings.xml
2012-02-23 15:13:33, DEBUG : Reading XML file: //192.168.44.1/install/wpkg/packages.xml
2012-02-23 15:13:33, *ERROR : Error parsing xml '//192.168.44.1/install/wpkg/packages.xml*': Das Stylesheet enth▒lt kein Dokumentelement. [... etc.]
2012-02-23 15:13:33, *ERROR : No root element found in '//192.168.44.1/install/wpkg/packages.xml'*.

For now, I patched loadXml() to only try to load the xml if the file actually exists. Otherwise, print debug info and skip it. Now I have this in the log, which seems better:

2012-02-23 21:00:29, DEBUG   : Reading XML file: //192.168.44.1/install/wpkg/packages/twixtel.xml
2012-02-23 21:00:29, DEBUG   : Reading XML file: //192.168.44.1/install/wpkg/packages/user-settings.xml
2012-02-23 21:00:29, *DEBUG   : Skipping non-existing XML file: //192.168.44.1/install/wpkg/packages.xml*


This is the change I did to wpkg.js version 1.3.0:

====================================

$ diff -u wpkg.js.orig wpkg.js
--- wpkg.js.orig    2011-12-08 15:03:24.000000000 +0100
+++ wpkg.js    2012-02-23 20:40:14.000000000 +0100
@@ -7740,7 +7740,14 @@

      for( var i=0; i < filePaths.length; i++) {
          var filePath = filePaths[i];
-        dinfo("Reading XML file: " + filePath);
+        var fso = new ActiveXObject("Scripting.FileSystemObject")
+        if (fso.FileExists(filePath)) {
+            dinfo("Reading XML file: " + filePath);
+        } else {
+            dinfo("Skipping non-existing XML file: " + filePath);
+            continue;
+        }
+

          // Read XML file from file system.
          var xsl = new ActiveXObject("Msxml2.DOMDocument.3.0");

====================================

Maybe the line

var fso = new ActiveXObject("Scripting.FileSystemObject")

should be moved before the for loop for efficiency?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wpkg.org/pipermail/wpkg-users/attachments/20120223/fd5bdd3c/attachment-0001.html>


More information about the wpkg-users mailing list