Skip to content

Commit 7a73a2f

Browse files
piscisaureusry
authored andcommitted
Refactor error to use dynamic dispatch and traits
This is in preperation for dynamic import (denoland#1789), which is more easily implemented when errors are dynamic.
1 parent 079bdbb commit 7a73a2f

28 files changed

+904
-1060
lines changed

cli/compiler.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
2-
use crate::deno_error::err_check;
3-
use crate::deno_error::DenoError;
42
use crate::diagnostics::Diagnostic;
53
use crate::msg;
64
use crate::resources;
@@ -9,6 +7,7 @@ use crate::state::*;
97
use crate::tokio_util;
108
use crate::worker::Worker;
119
use deno::Buf;
10+
use deno::ErrBox;
1211
use deno::ModuleSpecifier;
1312
use futures::Future;
1413
use futures::Stream;
@@ -96,7 +95,7 @@ pub fn bundle_async(
9695
state: ThreadSafeState,
9796
module_name: String,
9897
out_file: String,
99-
) -> impl Future<Item = (), Error = DenoError> {
98+
) -> impl Future<Item = (), Error = ErrBox> {
10099
debug!(
101100
"Invoking the compiler to bundle. module_name: {}",
102101
module_name
@@ -116,9 +115,9 @@ pub fn bundle_async(
116115
// as was done previously.
117116
state.clone(),
118117
);
119-
err_check(worker.execute("denoMain()"));
120-
err_check(worker.execute("workerMain()"));
121-
err_check(worker.execute("compilerMain()"));
118+
worker.execute("denoMain()").unwrap();
119+
worker.execute("workerMain()").unwrap();
120+
worker.execute("compilerMain()").unwrap();
122121

123122
let resource = worker.state.resource.clone();
124123
let compiler_rid = resource.rid;
@@ -144,7 +143,7 @@ pub fn bundle_async(
144143
let json_str = std::str::from_utf8(&msg).unwrap();
145144
debug!("Message: {}", json_str);
146145
if let Some(diagnostics) = Diagnostic::from_emit_result(json_str) {
147-
return Err(DenoError::from(diagnostics));
146+
return Err(ErrBox::from(diagnostics));
148147
}
149148
}
150149

@@ -156,7 +155,7 @@ pub fn bundle_async(
156155
pub fn compile_async(
157156
state: ThreadSafeState,
158157
module_meta_data: &ModuleMetaData,
159-
) -> impl Future<Item = ModuleMetaData, Error = DenoError> {
158+
) -> impl Future<Item = ModuleMetaData, Error = ErrBox> {
160159
let module_name = module_meta_data.module_name.clone();
161160

162161
debug!(
@@ -178,9 +177,9 @@ pub fn compile_async(
178177
// as was done previously.
179178
state.clone(),
180179
);
181-
err_check(worker.execute("denoMain()"));
182-
err_check(worker.execute("workerMain()"));
183-
err_check(worker.execute("compilerMain()"));
180+
worker.execute("denoMain()").unwrap();
181+
worker.execute("workerMain()").unwrap();
182+
worker.execute("compilerMain()").unwrap();
184183

185184
let compiling_job = state.progress.add("Compile", &module_name);
186185

@@ -211,7 +210,7 @@ pub fn compile_async(
211210
let json_str = std::str::from_utf8(&msg).unwrap();
212211
debug!("Message: {}", json_str);
213212
if let Some(diagnostics) = Diagnostic::from_emit_result(json_str) {
214-
return Err(DenoError::from(diagnostics));
213+
return Err(ErrBox::from(diagnostics));
215214
}
216215
}
217216

@@ -242,7 +241,7 @@ pub fn compile_async(
242241
pub fn compile_sync(
243242
state: ThreadSafeState,
244243
module_meta_data: &ModuleMetaData,
245-
) -> Result<ModuleMetaData, DenoError> {
244+
) -> Result<ModuleMetaData, ErrBox> {
246245
tokio_util::block_on(compile_async(state, module_meta_data))
247246
}
248247

0 commit comments

Comments
 (0)