Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k committed Sep 28, 2023
1 parent a297007 commit c699010
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
use crate::parser::DocParser;

use anyhow::anyhow;
use anyhow::Result;
use deno_graph::source::CacheSetting;
use deno_graph::source::LoadFuture;
use deno_graph::source::LoadResponse;
use deno_graph::source::Loader;
use deno_graph::source::ResolveError;
use deno_graph::source::Resolver;
use deno_graph::BuildOptions;
use deno_graph::CapturingModuleAnalyzer;
Expand Down Expand Up @@ -80,8 +80,11 @@ impl Resolver for ImportMapResolver {
&self,
specifier: &str,
referrer: &ModuleSpecifier,
) -> Result<ModuleSpecifier> {
Ok(self.0.resolve(specifier, referrer)?)
) -> Result<ModuleSpecifier, ResolveError> {
self
.0
.resolve(specifier, referrer)
.map_err(|err| ResolveError::Other(err.into()))
}
}

Expand All @@ -101,17 +104,20 @@ impl Resolver for JsResolver {
&self,
specifier: &str,
referrer: &ModuleSpecifier,
) -> Result<ModuleSpecifier> {
) -> Result<ModuleSpecifier, ResolveError> {
use ResolveError::*;
let this = JsValue::null();
let arg0 = JsValue::from(specifier);
let arg1 = JsValue::from(referrer.to_string());
let value = match self.resolve.call2(&this, &arg0, &arg1) {
Ok(value) => value,
Err(_) => return Err(anyhow!("JavaScript resolve() function threw.")),
Err(_) => {
return Err(Other(anyhow!("JavaScript resolve() function threw.")))
}
};
let value: String = serde_wasm_bindgen::from_value(value)
.map_err(|err| anyhow!("{}", err))?;
Ok(ModuleSpecifier::parse(&value)?)
ModuleSpecifier::parse(&value).map_err(|err| Other(err.into()))
}
}

Expand All @@ -122,7 +128,7 @@ pub async fn doc(
load: js_sys::Function,
maybe_resolve: Option<js_sys::Function>,
maybe_import_map: Option<String>,
) -> Result<JsValue, JsValue> {
) -> anyhow::Result<JsValue, JsValue> {
console_error_panic_hook::set_once();
let root_specifier = ModuleSpecifier::parse(&root_specifier)
.map_err(|err| JsValue::from(js_sys::Error::new(&err.to_string())))?;
Expand Down

0 comments on commit c699010

Please sign in to comment.