Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine CLI Errors. #2487

Merged
merged 10 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions cli/ansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,6 @@ pub fn red(s: String) -> impl fmt::Display {
style.paint(s)
}

pub fn grey(s: String) -> impl fmt::Display {
let mut style = Style::new();
if use_color() {
style = style.fg(Fixed(8));
}
style.paint(s)
}

pub fn bold(s: String) -> impl fmt::Display {
let mut style = Style::new();
if use_color() {
Expand Down
27 changes: 14 additions & 13 deletions cli/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// 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;
use crate::startup_data;
use crate::state::*;
use crate::tokio_util;
use crate::worker::Worker;
use deno::js_check;
use deno::Buf;
use futures::Future;
use futures::Stream;
Expand Down Expand Up @@ -92,7 +93,7 @@ pub fn bundle_async(
state: ThreadSafeState,
module_name: String,
out_file: String,
) -> impl Future<Item = (), Error = Diagnostic> {
) -> impl Future<Item = (), Error = DenoError> {
debug!(
"Invoking the compiler to bundle. module_name: {}",
module_name
Expand All @@ -112,9 +113,9 @@ pub fn bundle_async(
// as was done previously.
state.clone(),
);
js_check(worker.execute("denoMain()"));
js_check(worker.execute("workerMain()"));
js_check(worker.execute("compilerMain()"));
err_check(worker.execute("denoMain()"));
err_check(worker.execute("workerMain()"));
err_check(worker.execute("compilerMain()"));

let resource = worker.state.resource.clone();
let compiler_rid = resource.rid;
Expand All @@ -140,7 +141,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(diagnostics);
return Err(DenoError::from(diagnostics));
}
}

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

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

let compiling_job = state.progress.add(format!("Compiling {}", module_name));

Expand Down Expand Up @@ -205,7 +206,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(diagnostics);
return Err(DenoError::from(diagnostics));
}
}

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

Expand Down Expand Up @@ -306,6 +307,6 @@ mod tests {
]);
let out =
bundle_async(state, module_name, String::from("$deno$/bundle.js"));
assert_eq!(tokio_util::block_on(out), Ok(()));
assert!(tokio_util::block_on(out).is_ok());
}
}
30 changes: 22 additions & 8 deletions cli/deno_dir.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use crate::compiler::ModuleMetaData;
use crate::errors;
use crate::errors::DenoError;
use crate::errors::DenoResult;
use crate::errors::ErrorKind;
use crate::deno_error;
use crate::deno_error::DenoError;
use crate::deno_error::DenoResult;
use crate::deno_error::ErrorKind;
use crate::fs as deno_fs;
use crate::http_util;
use crate::js_errors::SourceMapGetter;
use crate::msg;
use crate::progress::Progress;
use crate::source_maps::SourceMapGetter;
use crate::tokio_util;
use crate::version;
use dirs;
Expand Down Expand Up @@ -152,7 +152,7 @@ impl DenoDir {
referrer: &str,
use_cache: bool,
no_fetch: bool,
) -> impl Future<Item = ModuleMetaData, Error = errors::DenoError> {
) -> impl Future<Item = ModuleMetaData, Error = deno_error::DenoError> {
debug!(
"fetch_module_meta_data. specifier {} referrer {}",
specifier, referrer
Expand Down Expand Up @@ -187,7 +187,7 @@ impl DenoDir {
Err(err) => {
if err.kind() == ErrorKind::NotFound {
// For NotFound, change the message to something better.
return Err(errors::new(
return Err(deno_error::new(
ErrorKind::NotFound,
format!(
"Cannot resolve module \"{}\" from \"{}\"",
Expand Down Expand Up @@ -255,7 +255,7 @@ impl DenoDir {
referrer: &str,
use_cache: bool,
no_fetch: bool,
) -> Result<ModuleMetaData, errors::DenoError> {
) -> Result<ModuleMetaData, deno_error::DenoError> {
tokio_util::block_on(
self
.fetch_module_meta_data_async(specifier, referrer, use_cache, no_fetch),
Expand Down Expand Up @@ -349,6 +349,20 @@ impl SourceMapGetter for DenoDir {
},
}
}

fn get_source_line(&self, script_name: &str, line: usize) -> Option<String> {
match self.fetch_module_meta_data(script_name, ".", true, true) {
Ok(out) => match str::from_utf8(&out.source_code) {
Ok(v) => {
let lines: Vec<&str> = v.lines().collect();
assert!(lines.len() > line);
Some(lines[line].to_string())
}
_ => None,
},
_ => None,
}
}
}

/// This fetches source code, locally or remotely.
Expand Down
Loading