From 28fc8248f0fe6fdc5a69d2063b50f3cd7226ae23 Mon Sep 17 00:00:00 2001
From: Jonas Jenwald <jonas.jenwald@gmail.com>
Date: Fri, 25 Feb 2022 16:53:28 +0100
Subject: [PATCH] Simplify the `wrapReason` helper function

All call-sites that use `wrapReason` should be passing a (possibly cloned) `Error` to the helper function, hence we shouldn't need to have a fallback code-path for any other data.
Note that for the `cancel`/`error` methods on Streams, since PR 11115 we've been asserting that the argument is in fact an `Error` as intended.
When calling `wrapReason` from *rejected* Promises, we should also be guaranteed that an `Error` is provided thanks to the ESLint rules `no-throw-literal` and `prefer-promise-reject-errors`.
---
 src/shared/message_handler.js | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/src/shared/message_handler.js b/src/shared/message_handler.js
index 15d73b9ce..111dbf7b9 100644
--- a/src/shared/message_handler.js
+++ b/src/shared/message_handler.js
@@ -21,7 +21,7 @@ import {
   PasswordException,
   UnexpectedResponseException,
   UnknownErrorException,
-  warn,
+  unreachable,
 } from "./util.js";
 
 const CallbackKind = {
@@ -49,16 +49,9 @@ function wrapReason(reason) {
       (typeof reason === "object" && reason !== null)
     )
   ) {
-    if (
-      typeof PDFJSDev === "undefined" ||
-      PDFJSDev.test("!PRODUCTION || TESTING")
-    ) {
-      throw new Error(
-        'wrapReason: Expected "reason" to be a (possibly cloned) Error.'
-      );
-    }
-    warn('wrapReason: Expected "reason" to be a (possibly cloned) Error.');
-    return reason;
+    unreachable(
+      'wrapReason: Expected "reason" to be a (possibly cloned) Error.'
+    );
   }
   switch (reason.name) {
     case "AbortException":