// Copyright 2018-2025 the Deno authors. MIT license. use std::convert::Infallible; use std::fmt::Debug; use std::fmt::Display; use deno_core::error::AnyError; use deno_core::error::CoreError; use deno_error::JsErrorBox; use deno_error::JsErrorClass; pub trait InfallibleResultExt { fn unwrap_infallible(self) -> T; } impl InfallibleResultExt for Result { fn unwrap_infallible(self) -> T { match self { Ok(value) => value, Err(never) => match never {}, } } } pub fn any_and_jserrorbox_downcast_ref< E: Display + Debug + Send + Sync + 'static, >( err: &AnyError, ) -> Option<&E> { err .downcast_ref::() .or_else(|| { err .downcast_ref::() .and_then(|e| e.as_any().downcast_ref::()) }) .or_else(|| { err.downcast_ref::().and_then(|e| match e { CoreError::JsNative(e) => e.as_any().downcast_ref::(), _ => None, }) }) }