Bug 1411552 - Improve the warning about attempting to overwrite prefs with a pref of the wrong type. r=njn
authorJonathan Watt <jwatt@jwatt.org>
Wed, 11 Oct 2017 19:10:43 +0100
changeset 390724 49451ebb746c027e54388d572e40be5489233d60
parent 390723 60fd4a5b01ec70ded9ddfd560fd5be191b1c74b9
child 390725 dc16f72054aaabfa0dba46155bf1524b19fffe6f
push id97097
push userjwatt@jwatt.org
push dateWed, 08 Nov 2017 11:34:52 +0000
treeherdermozilla-inbound@b8d6110960ac [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1411552
milestone58.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 1411552 - Improve the warning about attempting to overwrite prefs with a pref of the wrong type. r=njn MozReview-Commit-ID: AAlimIWoOgQ
modules/libpref/Preferences.cpp
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -159,16 +159,35 @@ union PrefValue {
 enum class PrefType
 {
   Invalid = 0,
   String = 1,
   Int = 2,
   Bool = 3,
 };
 
+#ifdef DEBUG
+const char*
+PrefTypeToString(PrefType aType)
+{
+  switch (aType) {
+    case PrefType::Invalid:
+      return "INVALID";
+    case PrefType::String:
+      return "string";
+    case PrefType::Int:
+      return "int";
+    case PrefType::Bool:
+      return "bool";
+    default:
+      MOZ_CRASH("Unhandled enum value");
+  }
+}
+#endif
+
 // Keep the type of the preference, as well as the flags guiding its behaviour.
 class PrefTypeFlags
 {
 public:
   PrefTypeFlags()
     : mValue(AsInt(PrefType::Invalid))
   {
   }
@@ -974,18 +993,21 @@ pref_HashPref(const char* aKey,
     pref->mKey = ArenaStrdup(aKey, gPrefNameArena);
     memset(&pref->mDefaultPref, 0, sizeof(pref->mDefaultPref));
     memset(&pref->mUserPref, 0, sizeof(pref->mUserPref));
 
   } else if (pref->mPrefFlags.HasDefault() &&
              !pref->mPrefFlags.IsPrefType(aType)) {
     NS_WARNING(
       nsPrintfCString(
-        "Trying to overwrite value of default pref %s with the wrong type!",
-        aKey)
+        "Ignoring attempt to overwrite value of default pref %s (type %s) with "
+        "the wrong type (%s)!",
+        aKey,
+        PrefTypeToString(pref->mPrefFlags.GetPrefType()),
+        PrefTypeToString(aType))
         .get());
 
     return NS_ERROR_UNEXPECTED;
   }
 
   bool valueChanged = false;
   if (aFlags & kPrefSetDefault) {
     if (!pref->mPrefFlags.IsLocked()) {