Bug 1720047 - Show warning message in debug if unset nsMsgHdr.messageOffset is read. r=mkmelin
authorBen Campbell <benc@thunderbird.net>
Fri, 26 Nov 2021 12:39:18 +0200
changeset 34405 8c44f53caece8bfd13295337d23deba36dbc92ca
parent 34404 00f717697e19f53b047e847bf0e3aa364b052902
child 34406 0295d55c1fdea60192d6518ec9fe23a8664f1966
push id19411
push usermkmelin@iki.fi
push dateFri, 26 Nov 2021 10:39:40 +0000
treeherdercomm-central@8c44f53caece [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1720047
Bug 1720047 - Show warning message in debug if unset nsMsgHdr.messageOffset is read. r=mkmelin Differential Revision: https://phabricator.services.mozilla.com/D131571
mailnews/db/msgdb/src/nsMsgHdr.cpp
--- a/mailnews/db/msgdb/src/nsMsgHdr.cpp
+++ b/mailnews/db/msgdb/src/nsMsgHdr.cpp
@@ -8,17 +8,19 @@
 #include "nsMsgHdr.h"
 #include "nsMsgDatabase.h"
 #include "nsMsgUtils.h"
 #include "nsMsgMessageFlags.h"
 #include "nsIMsgThread.h"
 #include "nsMsgMimeCID.h"
 #include "mozilla/Attributes.h"
 #include "nsStringEnumerator.h"
-
+#ifdef DEBUG
+#  include "nsPrintfCString.h"
+#endif
 using namespace mozilla::mailnews;
 
 NS_IMPL_ISUPPORTS(nsMsgHdr, nsIMsgDBHdr)
 
 #define FLAGS_INITED 0x1
 #define CACHED_VALUES_INITED 0x2
 #define REFERENCES_INITED 0x4
 #define THREAD_PARENT_INITED 0x8
@@ -427,20 +429,35 @@ NS_IMETHODIMP nsMsgHdr::GetAccountKey(ch
   NS_ENSURE_ARG_POINTER(aResult);
 
   return GetStringProperty("account", aResult);
 }
 
 NS_IMETHODIMP nsMsgHdr::GetMessageOffset(uint64_t* result) {
   NS_ENSURE_ARG(result);
 
-  // if there is a message offset, use it, otherwise, we'll use the message key.
   (void)GetUInt64Column(m_mdb->m_offlineMsgOffsetColumnToken, result,
                         (unsigned)-1);
-  if (*result == (unsigned)-1) *result = m_messageKey;
+  if (*result == (unsigned)-1) {
+    // It's unset. Unfortunately there's not much we can do here. There's
+    // a lot of code which relies on being able to read .messageOffset,
+    // even if it doesn't require it to return anything sensible.
+    // (For example - in js unit tests - Assert.equals() stringifies the
+    // attributes of it's expected/actual values to produce an error
+    // message even if the assert passes).
+#ifdef DEBUG
+    nsCString tok;
+    GetStringProperty("storeToken", getter_Copies(tok));
+    nsPrintfCString err("Missing .messageOffset (key=%u, storeToken='%s')",
+                        m_messageKey, tok.get());
+    NS_WARNING(err.get());
+#endif
+    // Return something obviously broken.
+    *result = 12345678;
+  }
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgHdr::SetMessageOffset(uint64_t offset) {
   SetUInt64Column(offset, m_mdb->m_offlineMsgOffsetColumnToken);
   return NS_OK;
 }