Skip to content

Commit

Permalink
web: Show panics in console in prql-js
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty committed Aug 30, 2023
1 parent 9d5ed6c commit 819de87
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
12 changes: 9 additions & 3 deletions bindings/prql-js/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ prql-compiler = {path = "../../crates/prql-compiler", default-features = false}
wasm-bindgen = "0.2.87"

# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
# logging them with `console.error`. While the docs state that "This is great
# for development, but requires all the `std::fmt` and `std::panicking`
# infrastructure, so isn't great for code size when deploying.", on testing with
# `--no-default-features`,
# `prql/target/wasm32-unknown-unknown/release/prql_js.wasm` is 7.416MB vs
# 7.408MB. Maybe because we're already including lots of that with other library
# features? Even running `wasm-opt prql_js.wasm` makes similiarly sized files of
# 5.7M. Feel free to try removing this as part of reducing code size (would be
# good to have a much smaller code size...).
console_error_panic_hook = {version = "0.1.7", optional = true}

[target.'cfg(target_family="wasm")'.dev-dependencies]
Expand Down
9 changes: 7 additions & 2 deletions bindings/prql-js/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![cfg(target_family = "wasm")]

mod utils;

use std::str::FromStr;

use prql_compiler::Target;
Expand Down Expand Up @@ -117,6 +115,13 @@ impl From<CompileOptions> for prql_compiler::Options {
}

fn return_or_throw(result: Result<String, prql_compiler::ErrorMessages>) -> Option<String> {
// When the `console_error_panic_hook` feature is enabled, we can call the
// `set_panic_hook` function at least once during initialization, and then
// we will get better error messages if our code ever panics. See
// `Cargo.toml` for notes.
#[cfg(feature = "console_error_panic_hook")]
console_error_panic_hook::set_once();

match result {
Ok(sql) => Some(sql),
Err(e) => wasm_bindgen::throw_str(&e.to_json()),
Expand Down
11 changes: 0 additions & 11 deletions bindings/prql-js/src/utils.rs

This file was deleted.

0 comments on commit 819de87

Please sign in to comment.