Bug 1188982 - Provide better diagnostics when failing to load a source; r=tromey
authorNick Fitzgerald <fitzgen@gmail.com>
Tue, 04 Aug 2015 13:06:08 -0700
changeset 287794 b4db50d6a91edec44abff5e7ab55daa9b1f139dd
parent 287793 fffe3ac33207713a9d71fcddadeeb938e6221a2a
child 287795 e0c790a2af42f5b06643c0faa74db81d12664f47
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstromey
bugs1188982
milestone42.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 1188982 - Provide better diagnostics when failing to load a source; r=tromey
toolkit/devtools/server/actors/script.js
--- a/toolkit/devtools/server/actors/script.js
+++ b/toolkit/devtools/server/actors/script.js
@@ -2287,27 +2287,65 @@ SourceActor.prototype = {
           return;
         }
 
         this._addonPath = path;
       }
     }
   },
 
+  _reportLoadSourceError: function (error, map=null) {
+    try {
+      DevToolsUtils.reportException("SourceActor", error);
+
+      JSON.stringify(this.form(), null, 4).split(/\n/g)
+        .forEach(line => console.error("\t", line));
+
+      if (!map) {
+        return;
+      }
+
+      console.error("\t", "source map's sourceRoot =", map.sourceRoot);
+
+      console.error("\t", "source map's sources =");
+      map.sources.forEach(s => {
+        let hasSourceContent = map.sourceContentFor(s, true);
+        console.error("\t\t", s, "\t",
+                      hasSourceContent ? "has source content" : "no source content");
+      });
+
+      console.error("\t", "source map's sourcesContent =");
+      map.sourcesContent.forEach(c => {
+        if (c.length > 80) {
+          c = c.slice(0, 77) + "...";
+        }
+        c = c.replace(/\n/g, "\\n");
+        console.error("\t\t", c);
+      });
+    } catch (e) { }
+  },
+
   _getSourceText: function () {
     let toResolvedContent = t => ({
       content: t,
       contentType: this._contentType
     });
 
     let genSource = this.generatedSource || this.source;
     return this.threadActor.sources.fetchSourceMap(genSource).then(map => {
-      let sc;
-      if (map && (sc = map.sourceContentFor(this.url))) {
-        return toResolvedContent(sc);
+      if (map) {
+        try {
+          let sourceContent = map.sourceContentFor(this.url);
+          if (sourceContent) {
+            return toResolvedContent(sourceContent);
+          }
+        } catch (error) {
+          this._reportLoadSourceError(error, map);
+          throw error;
+        }
       }
 
       // Use `source.text` if it exists, is not the "no source"
       // string, and the content type of the source is JavaScript. It
       // will be "no source" if the Debugger API wasn't able to load
       // the source because sources were discarded
       // (javascript.options.discardSystemSource == true). Re-fetch
       // non-JS sources to get the contentType from the headers.
@@ -2322,20 +2360,24 @@ SourceActor.prototype = {
         // there are inline sources). Otherwise, we can't trust the
         // cache because we are most likely here because we are
         // fetching the original text for sourcemapped code, and the
         // page hasn't requested it before (if it has, it was a
         // previous debugging session).
         let sourceFetched = fetch(this.url, { loadFromCache: this.isInlineSource });
 
         // Record the contentType we just learned during fetching
-        return sourceFetched.then(result => {
-          this._contentType = result.contentType;
-          return result;
-        });
+        return sourceFetched
+          .then(result => {
+            this._contentType = result.contentType;
+            return result;
+          }, error => {
+            this._reportLoadSourceError(error, map);
+            throw error;
+          });
       }
     });
   },
 
   /**
    * Get all executable lines from the current source
    * @return Array - Executable lines of the current script
    **/