Bug 1649477 - Part 4: Improve a couple of error messages, r=kmag
authorNika Layzell <nika@thelayzells.com>
Wed, 08 Jul 2020 14:22:23 +0000
changeset 539398 5907260fa4688e06eb4b07982ed23fc2d476d8e3
parent 539397 d7810f45f0cbbf63ec61112e4d5c16433640775b
child 539399 e3540b3df1814dca40f48340c3a4b53d2858d1b8
push id121100
push usernlayzell@mozilla.com
push dateWed, 08 Jul 2020 16:43:08 +0000
treeherderautoland@5907260fa468 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1649477
milestone80.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 1649477 - Part 4: Improve a couple of error messages, r=kmag Differential Revision: https://phabricator.services.mozilla.com/D82103
dom/ipc/jsactor/JSActor.cpp
--- a/dom/ipc/jsactor/JSActor.cpp
+++ b/dom/ipc/jsactor/JSActor.cpp
@@ -65,17 +65,18 @@ void JSActor::StartDestroy() {
 void JSActor::AfterDestroy() {
   mCanSend = false;
 
   // Take our queries out, in case somehow rejecting promises can trigger
   // additions or removals.
   nsRefPtrHashtable<nsUint64HashKey, Promise> pendingQueries;
   mPendingQueries.SwapElements(pendingQueries);
   for (auto& entry : pendingQueries) {
-    entry.GetData()->MaybeReject(NS_ERROR_NOT_AVAILABLE);
+    entry.GetData()->MaybeRejectWithAbortError(nsPrintfCString(
+        "Actor '%s' destroyed before query was resolved", mName.get()));
   }
 
   InvokeCallback(CallbackFunction::DidDestroy);
   ClearManager();
 }
 
 void JSActor::InvokeCallback(CallbackFunction callback) {
   MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
@@ -187,17 +188,19 @@ static ipc::StructuredCloneData CaptureJ
   return CloneJSStack(aCx, stack);
 }
 
 void JSActor::SendAsyncMessage(JSContext* aCx, const nsAString& aMessageName,
                                JS::Handle<JS::Value> aObj, ErrorResult& aRv) {
   ipc::StructuredCloneData data;
   if (!nsFrameMessageManager::GetParamsForMessage(
           aCx, aObj, JS::UndefinedHandleValue, data)) {
-    aRv.Throw(NS_ERROR_DOM_DATA_CLONE_ERR);
+    aRv.ThrowDataCloneError(nsPrintfCString(
+        "Failed to serialize message '%s::%s'",
+        NS_LossyConvertUTF16toASCII(aMessageName).get(), mName.get()));
     return;
   }
 
   JSActorMessageMeta meta;
   meta.actorName() = mName;
   meta.messageName() = aMessageName;
   meta.kind() = JSActorMessageKind::Message;
 
@@ -206,23 +209,25 @@ void JSActor::SendAsyncMessage(JSContext
 
 already_AddRefed<Promise> JSActor::SendQuery(JSContext* aCx,
                                              const nsAString& aMessageName,
                                              JS::Handle<JS::Value> aObj,
                                              ErrorResult& aRv) {
   ipc::StructuredCloneData data;
   if (!nsFrameMessageManager::GetParamsForMessage(
           aCx, aObj, JS::UndefinedHandleValue, data)) {
-    aRv.Throw(NS_ERROR_DOM_DATA_CLONE_ERR);
+    aRv.ThrowDataCloneError(nsPrintfCString(
+        "Failed to serialize message '%s::%s'",
+        NS_LossyConvertUTF16toASCII(aMessageName).get(), mName.get()));
     return nullptr;
   }
 
   nsIGlobalObject* global = xpc::CurrentNativeGlobal(aCx);
   if (NS_WARN_IF(!global)) {
-    aRv.Throw(NS_ERROR_UNEXPECTED);
+    aRv.ThrowUnknownError("Unable to get current native global");
     return nullptr;
   }
 
   RefPtr<Promise> promise = Promise::Create(global, aRv);
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
@@ -290,31 +295,31 @@ void JSActor::ReceiveMessageOrQuery(JSCo
     }
   }
 }
 
 void JSActor::ReceiveQueryReply(JSContext* aCx,
                                 const JSActorMessageMeta& aMetadata,
                                 JS::Handle<JS::Value> aData, ErrorResult& aRv) {
   if (NS_WARN_IF(aMetadata.actorName() != mName)) {
-    aRv.Throw(NS_ERROR_UNEXPECTED);
+    aRv.ThrowUnknownError("Mismatched actor name for query reply");
     return;
   }
 
   RefPtr<Promise> promise;
   if (NS_WARN_IF(!mPendingQueries.Remove(aMetadata.queryId(),
                                          getter_AddRefs(promise)))) {
-    aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
+    aRv.ThrowUnknownError("Received reply for non-pending query");
     return;
   }
 
   JSAutoRealm ar(aCx, promise->PromiseObj());
   JS::RootedValue data(aCx, aData);
   if (NS_WARN_IF(!JS_WrapValue(aCx, &data))) {
-    aRv.Throw(NS_ERROR_FAILURE);
+    aRv.NoteJSContextException(aCx);
     return;
   }
 
   if (aMetadata.kind() == JSActorMessageKind::QueryResolve) {
     promise->MaybeResolve(data);
   } else {
     promise->MaybeReject(data);
   }