summaryrefslogtreecommitdiff
path: root/cli/ops/compiler.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/ops/compiler.rs')
-rw-r--r--cli/ops/compiler.rs28
1 files changed, 15 insertions, 13 deletions
diff --git a/cli/ops/compiler.rs b/cli/ops/compiler.rs
index 4d67a8009..a559bb539 100644
--- a/cli/ops/compiler.rs
+++ b/cli/ops/compiler.rs
@@ -4,6 +4,7 @@ use super::dispatch_json::JsonOp;
use super::dispatch_json::Value;
use crate::futures::future::try_join_all;
use crate::msg;
+use crate::op_error::OpError;
use crate::ops::json_op;
use crate::state::State;
use deno_core::Loader;
@@ -38,7 +39,7 @@ fn op_cache(
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
-) -> Result<JsonOp, ErrBox> {
+) -> Result<JsonOp, OpError> {
let args: CacheArgs = serde_json::from_value(args)?;
let module_specifier = ModuleSpecifier::resolve_url(&args.module_id)
@@ -66,7 +67,7 @@ fn op_resolve_modules(
state: &State,
args: Value,
_data: Option<ZeroCopyBuf>,
-) -> Result<JsonOp, ErrBox> {
+) -> Result<JsonOp, OpError> {
let args: SpecifiersReferrerArgs = serde_json::from_value(args)?;
let (referrer, is_main) = if let Some(referrer) = args.referrer {
(referrer, false)
@@ -77,11 +78,10 @@ fn op_resolve_modules(
let mut specifiers = vec![];
for specifier in &args.specifiers {
- let resolved_specifier = state.resolve(specifier, &referrer, is_main);
- match resolved_specifier {
- Ok(ms) => specifiers.push(ms.as_str().to_owned()),
- Err(err) => return Err(err),
- }
+ let specifier = state
+ .resolve(specifier, &referrer, is_main)
+ .map_err(OpError::from)?;
+ specifiers.push(specifier.as_str().to_owned());
}
Ok(JsonOp::Sync(json!(specifiers)))
@@ -91,7 +91,7 @@ fn op_fetch_source_files(
state: &State,
args: Value,
_data: Option<ZeroCopyBuf>,
-) -> Result<JsonOp, ErrBox> {
+) -> Result<JsonOp, OpError> {
let args: SpecifiersReferrerArgs = serde_json::from_value(args)?;
let ref_specifier = if let Some(referrer) = args.referrer {
@@ -122,7 +122,7 @@ fn op_fetch_source_files(
})
.collect();
- let files = try_join_all(file_futures).await?;
+ let files = try_join_all(file_futures).await.map_err(OpError::from)?;
// We want to get an array of futures that resolves to
let v = files.into_iter().map(|f| {
async {
@@ -134,7 +134,8 @@ fn op_fetch_source_files(
global_state
.file_fetcher
.fetch_source_file_async(&types_specifier, ref_specifier.clone())
- .await?
+ .await
+ .map_err(OpError::from)?
}
_ => f,
};
@@ -146,12 +147,13 @@ fn op_fetch_source_files(
global_state
.wasm_compiler
.compile_async(global_state.clone(), &file)
- .await?
+ .await
+ .map_err(|e| OpError::other(e.to_string()))?
.code
}
_ => String::from_utf8(file.source_code).unwrap(),
};
- Ok::<_, ErrBox>(json!({
+ Ok::<_, OpError>(json!({
"url": file.url.to_string(),
"filename": file.filename.to_str().unwrap(),
"mediaType": file.media_type as i32,
@@ -177,7 +179,7 @@ fn op_fetch_asset(
_state: &State,
args: Value,
_data: Option<ZeroCopyBuf>,
-) -> Result<JsonOp, ErrBox> {
+) -> Result<JsonOp, OpError> {
let args: FetchRemoteAssetArgs = serde_json::from_value(args)?;
debug!("args.name: {}", args.name);