Bug 1341452 - Write nsresult name in MediaResult::Description() - r=jya
authorGerald Squelart <gsquelart@mozilla.com>
Tue, 21 Feb 2017 16:30:44 +1100
changeset 373368 76b0a067ca5143487ed6968dab76fbc7c4d45242
parent 373367 e14df54573698c69902c68b2f7b10b995cb39fd8
child 373369 5d1d3f47d4f73b7974e8f83b79f896c5b9534ae7
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1341452
milestone54.0a1
Bug 1341452 - Write nsresult name in MediaResult::Description() - r=jya Also only show the separator between code and message if there actually is a message. MozReview-Commit-ID: 6Cb4YnFi2fT
dom/media/MediaResult.h
--- a/dom/media/MediaResult.h
+++ b/dom/media/MediaResult.h
@@ -2,16 +2,18 @@
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MediaResult_h_
 #define MediaResult_h_
 
+#include "nsString.h" // Required before 'mozilla/ErrorNames.h'!?
+#include "mozilla/ErrorNames.h"
 #include "nsError.h"
 #include "nsPrintfCString.h"
 
 // MediaResult can be used interchangeably with nsresult.
 // It allows to store extra information such as where the error occurred.
 // While nsresult is typically passed by value; due to its potential size, using
 // MediaResult const references is recommended.
 namespace mozilla {
@@ -46,17 +48,23 @@ public:
   bool operator!=(nsresult aResult) const { return aResult != mCode; }
   operator nsresult () const { return mCode; }
 
   nsCString Description() const
   {
     if (NS_SUCCEEDED(mCode)) {
       return nsCString();
     }
-    return nsPrintfCString("0x%08" PRIx32 ": %s", static_cast<uint32_t>(mCode), mMessage.get());
+    nsCString name;
+    GetErrorName(mCode, static_cast<nsACString&>(name));
+    return nsPrintfCString("%s (0x%08" PRIx32 ")%s%s",
+                           name.get(),
+                           static_cast<uint32_t>(mCode),
+                           mMessage.IsEmpty() ? "" : " - ",
+                           mMessage.get());
   }
 
 private:
   nsresult mCode;
   nsCString mMessage;
 };
 
 #ifdef _MSC_VER