From 44a1bc539644b4e24d8cdb4fa355e71c36ce7247 Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Tue, 8 Mar 2011 18:51:15 -0500 Subject: [PATCH] scripting.js: small cleanups - Fix missing trailing semicolons - Catch when something results in metrics not being to avoid hard-to-debug JSON parse errors. https://bugzilla.gnome.org/show_bug.cgi?id=644265 --- js/ui/scripting.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/js/ui/scripting.js b/js/ui/scripting.js index 2e38d1087..1fc583ea7 100644 --- a/js/ui/scripting.js +++ b/js/ui/scripting.js @@ -246,8 +246,8 @@ function _collect(scriptModule, outputFile) { Shell.write_string_to_stream(out, '"events":\n'); Shell.PerfLog.get_default().dump_events(out); - let monitors = global.get_monitors() - let primary = global.get_primary_monitor() + let monitors = global.get_monitors(); + let primary = global.get_primary_monitor(); Shell.write_string_to_stream(out, ',\n"monitors":\n['); for (let i = 0; i < monitors.length; i++) { let monitor = monitors[i]; @@ -266,7 +266,21 @@ function _collect(scriptModule, outputFile) { Shell.write_string_to_stream(out, ',\n"metrics":\n[ '); let first = true; for (let name in scriptModule.METRICS) { - let metric = scriptModule.METRICS[name]; + let metric = scriptModule.METRICS[name]; + // Extra checks here because JSON.stringify generates + // invalid JSON for undefined values + if (metric.description == null) { + log("Error: No description found for metric " + name); + continue; + } + if (metric.units == null) { + log("Error: No units found for metric " + name); + continue; + } + if (metric.value == null) { + log("Error: No value found for metric " + name); + continue; + } if (!first) Shell.write_string_to_stream(out, ',\n ');