mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 07:44:48 -05:00
Better error message for bad filename CLI argument.
This commit is contained in:
parent
98d20cd178
commit
4b61170e22
7 changed files with 42 additions and 25 deletions
|
@ -180,6 +180,7 @@ pub fn permission_denied() -> DenoError {
|
|||
)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum RustOrJsError {
|
||||
Rust(DenoError),
|
||||
Js(JSError),
|
||||
|
@ -196,3 +197,12 @@ impl From<JSError> for RustOrJsError {
|
|||
RustOrJsError::Js(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for RustOrJsError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
RustOrJsError::Rust(e) => e.fmt(f),
|
||||
RustOrJsError::Js(e) => e.fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -404,17 +404,19 @@ impl Isolate {
|
|||
&mut self,
|
||||
js_filename: &str,
|
||||
is_prefetch: bool,
|
||||
) -> Result<(), JSError> {
|
||||
let out =
|
||||
code_fetch_and_maybe_compile(&self.state, js_filename, ".").unwrap();
|
||||
) -> Result<(), RustOrJsError> {
|
||||
let out = code_fetch_and_maybe_compile(&self.state, js_filename, ".")
|
||||
.map_err(RustOrJsError::from)?;
|
||||
|
||||
let id = self.mod_new(out.filename.clone(), out.js_source())?;
|
||||
let id = self
|
||||
.mod_new(out.filename.clone(), out.js_source())
|
||||
.map_err(RustOrJsError::from)?;
|
||||
|
||||
self.mod_load_deps(id).ok();
|
||||
self.mod_load_deps(id)?;
|
||||
|
||||
self.mod_instantiate(id)?;
|
||||
self.mod_instantiate(id).map_err(RustOrJsError::from)?;
|
||||
if !is_prefetch {
|
||||
self.mod_evaluate(id)?;
|
||||
self.mod_evaluate(id).map_err(RustOrJsError::from)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ use source_map_mappings::parse_mappings;
|
|||
use source_map_mappings::Bias;
|
||||
use source_map_mappings::Mappings;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
|
||||
pub trait SourceMapGetter {
|
||||
/// Returns the raw source map file.
|
||||
|
@ -73,39 +74,34 @@ impl ToString for StackFrame {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToString for JSError {
|
||||
fn to_string(&self) -> String {
|
||||
// TODO Improve the formatting of these error messages.
|
||||
let mut s = String::new();
|
||||
|
||||
impl fmt::Display for JSError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if self.script_resource_name.is_some() {
|
||||
let script_resource_name = self.script_resource_name.as_ref().unwrap();
|
||||
// Avoid showing internal code from gen/bundle/main.js
|
||||
if script_resource_name != "gen/bundle/main.js" {
|
||||
s.push_str(script_resource_name);
|
||||
write!(f, "{}", script_resource_name)?;
|
||||
if self.line_number.is_some() {
|
||||
s.push_str(&format!(
|
||||
write!(
|
||||
f,
|
||||
":{}:{}",
|
||||
self.line_number.unwrap(),
|
||||
self.start_column.unwrap()
|
||||
));
|
||||
)?;
|
||||
assert!(self.start_column.is_some());
|
||||
}
|
||||
if self.source_line.is_some() {
|
||||
s.push_str("\n");
|
||||
s.push_str(self.source_line.as_ref().unwrap());
|
||||
s.push_str("\n\n");
|
||||
write!(f, "\n{}\n\n", self.source_line.as_ref().unwrap())?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s.push_str(&self.message);
|
||||
write!(f, "{}", &self.message)?;
|
||||
|
||||
for frame in &self.frames {
|
||||
s.push_str("\n");
|
||||
s.push_str(&frame.to_string());
|
||||
write!(f, "\n{}", &frame.to_string())?;
|
||||
}
|
||||
s
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ impl log::Log for Logger {
|
|||
fn flush(&self) {}
|
||||
}
|
||||
|
||||
fn print_err_and_exit(err: js_errors::JSError) {
|
||||
fn print_err_and_exit(err: errors::RustOrJsError) {
|
||||
eprintln!("{}", err.to_string());
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
@ -100,6 +100,7 @@ fn main() {
|
|||
// Setup runtime.
|
||||
isolate
|
||||
.execute("denoMain();")
|
||||
.map_err(errors::RustOrJsError::from)
|
||||
.unwrap_or_else(print_err_and_exit);
|
||||
|
||||
// Execute input file.
|
||||
|
@ -110,6 +111,9 @@ fn main() {
|
|||
.unwrap_or_else(print_err_and_exit);
|
||||
}
|
||||
|
||||
isolate.event_loop().unwrap_or_else(print_err_and_exit);
|
||||
isolate
|
||||
.event_loop()
|
||||
.map_err(errors::RustOrJsError::from)
|
||||
.unwrap_or_else(print_err_and_exit);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Uncaught Cannot resolve module "./bad-module.js" from "[WILDCARD]error_009_missing_js_module.js"
|
||||
Cannot resolve module "./bad-module.js" from "[WILDCARD]error_009_missing_js_module.js"
|
||||
|
|
1
tests/error_010_nonexistent_arg.out
Normal file
1
tests/error_010_nonexistent_arg.out
Normal file
|
@ -0,0 +1 @@
|
|||
[WILDCARD]Cannot resolve module "not-a-valid-filename.ts" from "."
|
4
tests/error_010_nonexistent_arg.test
Normal file
4
tests/error_010_nonexistent_arg.test
Normal file
|
@ -0,0 +1,4 @@
|
|||
args: not-a-valid-filename.ts
|
||||
output: tests/error_010_nonexistent_arg.out
|
||||
exit_code: 1
|
||||
check_stderr: true
|
Loading…
Reference in a new issue