From b892188878fd5a1a38a45d1c2e892c41be240ca0 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 16 Jul 2018 23:25:50 -0400 Subject: [PATCH] Better exception output. --- BUILD.gn | 10 ++++++++-- js/runtime.ts | 2 +- js/util.ts | 4 ++-- src/handlers.rs | 3 --- src/main.rs | 6 +++++- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 33cb4f7bd41b08..9c2fe5c1dc3df1 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -24,7 +24,10 @@ config("deno_config") { rust_executable("deno") { source_root = "src/main.rs" - extern = [ "$rust_build:libc" ] + extern = [ + "$rust_build:libc", + "$rust_build:log", + ] deps = [ ":libdeno", ] @@ -35,7 +38,10 @@ rust_executable("deno") { # extra process of building a snapshot and instead load the bundle from disk. rust_executable("deno_nosnapshot") { source_root = "src/main.rs" - extern = [ "$rust_build:libc" ] + extern = [ + "$rust_build:libc", + "$rust_build:log", + ] deps = [ ":libdeno_nosnapshot", ] diff --git a/js/runtime.ts b/js/runtime.ts index d234cdd85843c2..c439fb96311f8e 100644 --- a/js/runtime.ts +++ b/js/runtime.ts @@ -36,7 +36,7 @@ window.onerror = ( // Error.prepareStackTrace handler. Users will get unmapped stack traces on // uncaught exceptions until this issue is fixed. //Error.prepareStackTrace = null; - console.log(error.message, error.stack); + console.log(error.stack); os.exit(1); }; diff --git a/js/util.ts b/js/util.ts index 7216f9491335e6..05b243427c3a27 100644 --- a/js/util.ts +++ b/js/util.ts @@ -15,9 +15,9 @@ export function log(...args: any[]): void { } } -export function assert(cond: boolean, msg = "") { +export function assert(cond: boolean, msg = "assert") { if (!cond) { - throw Error(`Assert fail. ${msg}`); + throw Error(msg); } } diff --git a/src/handlers.rs b/src/handlers.rs index 4c4a791ea4f8af..a9221a8cb20c54 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -177,9 +177,6 @@ pub extern "C" fn handle_code_fetch( module_specifier_: *const c_char, containing_file_: *const c_char, ) { - // TODO(ry) Move this to main. - log::set_max_level(log::LevelFilter::Debug); - let module_specifier = string_from_ptr(module_specifier_); let containing_file = string_from_ptr(containing_file_); diff --git a/src/main.rs b/src/main.rs index 10b1aef81f8e83..3af29942842e89 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,6 @@ extern crate libc; +#[macro_use] +extern crate log; use libc::c_char; use libc::c_int; @@ -107,6 +109,8 @@ impl Drop for Deno { } fn main() { + log::set_max_level(log::LevelFilter::Debug); + unsafe { deno_init() }; set_flags(); @@ -122,7 +126,7 @@ fn main() { d.execute("deno_main.js", "denoMain();") .unwrap_or_else(|err| { - println!("Error {}\n", err); + error!("{}", err); std::process::exit(1); }); }