Bug 1345533 - report source map errors to the web console; r?bgrins draft
authorTom Tromey <tom@tromey.com>
Thu, 03 Aug 2017 09:00:19 -0600
changeset 621393 028c27d60ee608f1fba79f4289e571bebcde8199
parent 621287 9a4bb3a8be25bb0d463c79f803c71686faf0d735
child 621406 816bbf3c57873447a40927cb1a71c7eb3aa08b25
child 640995 7fbd925dc1c8df8dfed73fe30c2ba05b89aa69de
push id72357
push userbmo:ttromey@mozilla.com
push dateFri, 04 Aug 2017 19:24:59 +0000
reviewersbgrins
bugs1345533
milestone57.0a1
Bug 1345533 - report source map errors to the web console; r?bgrins MozReview-Commit-ID: 7gynPYFxyIv
devtools/client/framework/toolbox.js
devtools/client/locales/en-US/toolbox.properties
devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_sourcemap_error.js
devtools/client/webconsole/new-console-output/test/mochitest/test-sourcemap-error-01.html
devtools/client/webconsole/new-console-output/test/mochitest/test-sourcemap-error-01.js
devtools/client/webconsole/new-console-output/test/mochitest/test-sourcemap-error-02.html
devtools/client/webconsole/new-console-output/test/mochitest/test-sourcemap-error-02.js
--- a/devtools/client/framework/toolbox.js
+++ b/devtools/client/framework/toolbox.js
@@ -546,17 +546,22 @@ Toolbox.prototype = {
     // Uses browser loader to access the `Worker` global.
     let service = this.browserRequire("devtools/client/shared/source-map/index");
 
     // Provide a wrapper for the service that reports errors more nicely.
     this._sourceMapService = new Proxy(service, {
       get: (target, name) => {
         if (name === "getOriginalURLs") {
           return (urlInfo) => {
-            return target.getOriginalURLs(urlInfo).catch(console.error);
+            return target.getOriginalURLs(urlInfo)
+              .catch(text => {
+                let message = L10N.getFormatStr("toolbox.sourceMapFailure",
+                                                text, urlInfo.url, urlInfo.sourceMapURL);
+                this.target.logErrorInPage(message, "source map");
+              });
           };
         }
         return target[name];
       },
     });
 
     this._sourceMapService.startSourceMapWorker(SOURCE_MAP_WORKER);
     return this._sourceMapService;
--- a/devtools/client/locales/en-US/toolbox.properties
+++ b/devtools/client/locales/en-US/toolbox.properties
@@ -172,8 +172,15 @@ toolbox.noautohide.tooltip=Disable popup
 
 # LOCALIZATION NOTE (toolbox.closebutton.tooltip): This is the tooltip for
 # the close button the developer tools toolbox.
 toolbox.closebutton.tooltip=Close Developer Tools
 
 # LOCALIZATION NOTE (toolbox.allToolsButton.tooltip): This is the tooltip for the
 # "all tools" button displayed when some tools are hidden by overflow of the toolbar.
 toolbox.allToolsButton.tooltip=Select another tool
+
+# LOCALIZATION NOTE (toolbox.sourceMapFailure): This is shown in the web console
+# when there is a failure to fetch or parse a source map.
+# The text of the error: %1$S
+# The URL that caused DevTools to try to fetch a source map: %2$S
+# The URL of the source map itself: %3$S
+toolbox.sourceMapFailure=Source map error: %1$S\nResource URL: %2$S\nSource Map URL: %3$S
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
@@ -10,16 +10,20 @@ support-files =
   test-console-table.html
   test-location-debugger-link-console-log.js
   test-location-debugger-link-errors.js
   test-location-debugger-link.html
   test-location-styleeditor-link-1.css
   test-location-styleeditor-link-2.css
   test-location-styleeditor-link.html
   test-network-request.html
+  test-sourcemap-error-01.html
+  test-sourcemap-error-02.html
+  test-sourcemap-error-01.js
+  test-sourcemap-error-02.js
   test-stacktrace-location-debugger-link.html
   !/devtools/client/framework/test/shared-head.js
 
 [browser_jsterm_inspect.js]
 [browser_netmonitor_shows_reqs_in_webconsole.js]
 [browser_webconsole_batching.js]
 [browser_webconsole_console_dir.js]
 [browser_webconsole_console_group.js]
@@ -43,12 +47,13 @@ skip-if = (os == 'linux' && bits == 32 &
 [browser_webconsole_logErrorInPage.js]
 [browser_webconsole_network_messages_click.js]
 [browser_webconsole_nodes_highlight.js]
 [browser_webconsole_nodes_select.js]
 [browser_webconsole_object_inspector_entries.js]
 [browser_webconsole_object_inspector.js]
 [browser_webconsole_observer_notifications.js]
 [browser_webconsole_shows_reqs_in_netmonitor.js]
+[browser_webconsole_sourcemap_error.js]
 [browser_webconsole_stacktrace_location_debugger_link.js]
 [browser_webconsole_stacktrace_location_scratchpad_link.js]
 [browser_webconsole_string.js]
 [browser_webconsole_timestamps.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_sourcemap_error.js
@@ -0,0 +1,22 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Test that a missing source map is reported.
+
+const BASE = "http://example.com/browser/devtools/client/webconsole/new-console-output/test/mochitest/";
+
+add_task(async function () {
+  for (let test of ["test-sourcemap-error-01.html", "test-sourcemap-error-02.html"]) {
+    const hud = await openNewTabAndConsole(BASE + test);
+
+    const node = await waitFor(() => findMessage(hud, "here"));
+    ok(node, "logged text is displayed in web console");
+
+    const node2 = await waitFor(() => findMessage(hud, "Source map error"));
+    ok(node2, "source map error is displayed in web console");
+  }
+});
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/test-sourcemap-error-01.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <title>Test that a missing source map is reported to the console</title>
+<!-- Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/ -->
+    <script type="text/javascript" src="test-sourcemap-error-01.js"></script>
+  </head>
+  <body>
+    <p>Web Console test for source map failure.</p>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/test-sourcemap-error-01.js
@@ -0,0 +1,7 @@
+"use strict";
+window.qqz = function () {
+  console.log("here");
+};
+window.qqz();
+/* eslint-disable spaced-comment */
+//# sourceMappingURL=no-such-file.js.map
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/test-sourcemap-error-02.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <title>Test that an invalid source map URL is reported to the console</title>
+<!-- Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/ -->
+    <script type="text/javascript" src="test-sourcemap-error-02.js"></script>
+  </head>
+  <body>
+    <p>Web Console test for source map failure.</p>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/test-sourcemap-error-02.js
@@ -0,0 +1,7 @@
+"use strict";
+window.qqz = function () {
+  console.log("here");
+};
+window.qqz();
+/* eslint-disable spaced-comment */
+//# sourceMappingURL=data:invalid