Skip to content

Commit

Permalink
Merge #792
Browse files Browse the repository at this point in the history
792: Remove colored CLI output from wasmer-runtime-core lib r=syrusakbary a=repi

When the colored output was originally added in #489 and there was a discussion then about that it should ideally be in a higher-level crate rather than in the runtime-core library crate.

I agree with that, users of the library shouldn't be required to bring in the `colored` crate dependency and ideally also not have stdout/stderr output either, that should be controlled by the application that uses wasmer-runtime-core, not the library.

Disabling stdout/stderr output would be more intrusive but I wanted to at least not have colored output and another crate dependency so this change removes the colored output and the `colored` crate.

`colored` also had quite a few dependencies and, while well used, is not super actively maintained. So this change also removes 6 transitive dependencies of the `colored` crate which is great.

This could potentially be a feature flag instead also, but would be a bit messier.

Co-authored-by: Johan Andersson <repi@repi.se>
  • Loading branch information
bors[bot] and repi authored Sep 19, 2019
2 parents 0ea5b1b + 8d0edc6 commit 299fac9
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 91 deletions.
69 changes: 0 additions & 69 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion lib/runtime-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ libc = "0.2.60"
hex = "0.3.2"
smallvec = "0.6.10"
bincode = "1.1"
colored = "1.8"

[dependencies.indexmap]
version = "1.2.0"
Expand Down
3 changes: 0 additions & 3 deletions lib/runtime-core/src/fault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,10 @@ extern "C" fn signal_trap_handler(
let image = build_instance_image(ctx, es_image);
unwind_result = Box::new(image);
} else {
use colored::*;
if es_image.frames.len() > 0 {
eprintln!(
"\n{}",
"Wasmer encountered an error while running your WebAssembly program."
.bold()
.red()
);
es_image.print_backtrace_if_needed();
}
Expand Down
24 changes: 8 additions & 16 deletions lib/runtime-core/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,17 +303,15 @@ impl ExecutionStateImage {

if let Ok(x) = env::var("WASMER_BACKTRACE") {
if x == "1" {
eprintln!("{}", self.colored_output());
eprintln!("{}", self.output());
return;
}
}

eprintln!("Run with `WASMER_BACKTRACE=1` environment variable to display a backtrace.");
}

pub fn colored_output(&self) -> String {
use colored::*;

pub fn output(&self) -> String {
fn join_strings(x: impl Iterator<Item = String>, sep: &str) -> String {
let mut ret = String::new();
let mut first = true;
Expand Down Expand Up @@ -341,8 +339,6 @@ impl ExecutionStateImage {
i,
x.map(|x| format!("{}", x))
.unwrap_or_else(|| "?".to_string())
.bold()
.cyan()
)
}),
", ",
Expand All @@ -353,27 +349,23 @@ impl ExecutionStateImage {
let mut ret = String::new();

if self.frames.len() == 0 {
ret += &"Unknown fault address, cannot read stack.".yellow();
ret += &"Unknown fault address, cannot read stack.";
ret += "\n";
} else {
ret += &"Backtrace:".bold();
ret += &"Backtrace:";
ret += "\n";
for (i, f) in self.frames.iter().enumerate() {
ret += &format!("* Frame {} @ Local function {}", i, f.local_function_id).bold();
ret += &format!("* Frame {} @ Local function {}", i, f.local_function_id);
ret += "\n";
ret += &format!(" {} {}\n", "Offset:", format!("{}", f.wasm_inst_offset),);
ret += &format!(
" {} {}\n",
"Offset:".bold().yellow(),
format!("{}", f.wasm_inst_offset).bold().cyan(),
);
ret += &format!(
" {} {}\n",
"Locals:".bold().yellow(),
"Locals:",
format_optional_u64_sequence(&f.locals)
);
ret += &format!(
" {} {}\n\n",
"Stack:".bold().yellow(),
"Stack:",
format_optional_u64_sequence(&f.stack)
);
}
Expand Down
1 change: 0 additions & 1 deletion lib/singlepass-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ byteorder = "1.3.2"
nix = "0.15.0"
libc = "0.2.60"
smallvec = "0.6.10"
colored = "1.8"
2 changes: 1 addition & 1 deletion src/bin/wasmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ fn interactive_shell(mut ctx: InteractiveShellContext) -> ShellExitOperation {
}
"backtrace" | "bt" => {
if let Some(ref image) = ctx.image {
println!("{}", image.execution_state.colored_output());
println!("{}", image.execution_state.output());
} else {
println!("State not available");
}
Expand Down

0 comments on commit 299fac9

Please sign in to comment.