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`.
This commit is contained in:
		
							parent
							
								
									b753271ca6
								
							
						
					
					
						commit
						28fc8248f0
					
				@ -21,7 +21,7 @@ import {
 | 
				
			|||||||
  PasswordException,
 | 
					  PasswordException,
 | 
				
			||||||
  UnexpectedResponseException,
 | 
					  UnexpectedResponseException,
 | 
				
			||||||
  UnknownErrorException,
 | 
					  UnknownErrorException,
 | 
				
			||||||
  warn,
 | 
					  unreachable,
 | 
				
			||||||
} from "./util.js";
 | 
					} from "./util.js";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const CallbackKind = {
 | 
					const CallbackKind = {
 | 
				
			||||||
@ -49,16 +49,9 @@ function wrapReason(reason) {
 | 
				
			|||||||
      (typeof reason === "object" && reason !== null)
 | 
					      (typeof reason === "object" && reason !== null)
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
  ) {
 | 
					  ) {
 | 
				
			||||||
    if (
 | 
					    unreachable(
 | 
				
			||||||
      typeof PDFJSDev === "undefined" ||
 | 
					      'wrapReason: Expected "reason" to be a (possibly cloned) Error.'
 | 
				
			||||||
      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;
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  switch (reason.name) {
 | 
					  switch (reason.name) {
 | 
				
			||||||
    case "AbortException":
 | 
					    case "AbortException":
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user