Skip to content

Commit

Permalink
Refactor error to use dynamic dispatch and traits
Browse files Browse the repository at this point in the history
This is in preperation for dynamic import (#1789), which is more easily
implemented when errors are dynamic.
  • Loading branch information
piscisaureus authored and ry committed Jul 11, 2019
1 parent db5c66a commit abe8a11
Show file tree
Hide file tree
Showing 28 changed files with 904 additions and 1,060 deletions.
25 changes: 12 additions & 13 deletions cli/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use crate::deno_error::err_check;
use crate::deno_error::DenoError;
use crate::diagnostics::Diagnostic;
use crate::msg;
use crate::resources;
Expand All @@ -9,6 +7,7 @@ use crate::state::*;
use crate::tokio_util;
use crate::worker::Worker;
use deno::Buf;
use deno::ErrBox;
use deno::ModuleSpecifier;
use futures::Future;
use futures::Stream;
Expand Down Expand Up @@ -96,7 +95,7 @@ pub fn bundle_async(
state: ThreadSafeState,
module_name: String,
out_file: String,
) -> impl Future<Item = (), Error = DenoError> {
) -> impl Future<Item = (), Error = ErrBox> {
debug!(
"Invoking the compiler to bundle. module_name: {}",
module_name
Expand All @@ -116,9 +115,9 @@ pub fn bundle_async(
// as was done previously.
state.clone(),
);
err_check(worker.execute("denoMain()"));
err_check(worker.execute("workerMain()"));
err_check(worker.execute("compilerMain()"));
worker.execute("denoMain()").unwrap();
worker.execute("workerMain()").unwrap();
worker.execute("compilerMain()").unwrap();

let resource = worker.state.resource.clone();
let compiler_rid = resource.rid;
Expand All @@ -144,7 +143,7 @@ pub fn bundle_async(
let json_str = std::str::from_utf8(&msg).unwrap();
debug!("Message: {}", json_str);
if let Some(diagnostics) = Diagnostic::from_emit_result(json_str) {
return Err(DenoError::from(diagnostics));
return Err(ErrBox::from(diagnostics));
}
}

Expand All @@ -156,7 +155,7 @@ pub fn bundle_async(
pub fn compile_async(
state: ThreadSafeState,
module_meta_data: &ModuleMetaData,
) -> impl Future<Item = ModuleMetaData, Error = DenoError> {
) -> impl Future<Item = ModuleMetaData, Error = ErrBox> {
let module_name = module_meta_data.module_name.clone();

debug!(
Expand All @@ -178,9 +177,9 @@ pub fn compile_async(
// as was done previously.
state.clone(),
);
err_check(worker.execute("denoMain()"));
err_check(worker.execute("workerMain()"));
err_check(worker.execute("compilerMain()"));
worker.execute("denoMain()").unwrap();
worker.execute("workerMain()").unwrap();
worker.execute("compilerMain()").unwrap();

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

Expand Down Expand Up @@ -211,7 +210,7 @@ pub fn compile_async(
let json_str = std::str::from_utf8(&msg).unwrap();
debug!("Message: {}", json_str);
if let Some(diagnostics) = Diagnostic::from_emit_result(json_str) {
return Err(DenoError::from(diagnostics));
return Err(ErrBox::from(diagnostics));
}
}

Expand Down Expand Up @@ -242,7 +241,7 @@ pub fn compile_async(
pub fn compile_sync(
state: ThreadSafeState,
module_meta_data: &ModuleMetaData,
) -> Result<ModuleMetaData, DenoError> {
) -> Result<ModuleMetaData, ErrBox> {
tokio_util::block_on(compile_async(state, module_meta_data))
}

Expand Down
Loading

1 comment on commit abe8a11

@ry
Copy link
Member

@ry ry commented on abe8a11 Jul 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit resulted in a slightly bigger binary size: 45.9 -> 46.7
It's inconsequential, but I don't really understand why.

Screen Shot 2019-07-11 at 3 28 31 PM

Edit: it's probably from the Rust 1.36 upgrade rather than the this commit

Please sign in to comment.