Bug 1345533 - report source map errors to the web console; r=bgrins
authorTom Tromey <tom@tromey.com>
Thu, 03 Aug 2017 09:00:19 -0600
changeset 373011 82c5a8086a645f81713c87fe63b9ef4d75dbbb08
parent 373010 0c405b138c2b2a183d3c8a444dd09c3c066a04a5
child 373012 50efa6725f5d2660ee43b28d7e46f200fcf2e70d
push id48065
push userttromey@mozilla.com
push dateFri, 04 Aug 2017 23:22:02 +0000
treeherderautoland@82c5a8086a64 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins
bugs1345533
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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,13 +47,14 @@ 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]
 [browser_webconsole_warn_about_replaced_api.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