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

feat: Allow prqlc to print backtraces on errors #2751

Merged
merged 6 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
15 changes: 14 additions & 1 deletion prql-compiler/prqlc/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ use ariadne::Source;
use clap::{CommandFactory, Parser, Subcommand, ValueHint};
use clio::Output;
use itertools::Itertools;
use std::backtrace;
use std::fs::File;
use std::io::Write;
use std::ops::Range;
use std::path::PathBuf;
use std::process::exit;
use std::str::FromStr;
use std::{fs::File, ops::Range};

use prql_compiler::semantic::{self, reporting::*};
use prql_compiler::{ast::pl::Lineage, pl_to_prql};
Expand All @@ -27,6 +29,17 @@ pub fn main() -> color_eyre::eyre::Result<()> {

if let Err(error) = cli.command.run() {
eprintln!("{error}");
// TODO: this is clunky — we're using `backtrace.status()` to check if
// backtraces are enabled, but then printing the backtrace from the
// error. Is there a way to check whether backtrades are enabled without
// capturing another one; e.g. from the error itself?
max-sixty marked this conversation as resolved.
Show resolved Hide resolved
//
// Without this, we get a `<disabled>` message most of the time, which
// is kinda confusing.
if let backtrace::BacktraceStatus::Captured = backtrace::Backtrace::capture().status() {
eprintln!("{:#}", error.backtrace());
}

exit(1)
}

Expand Down
4 changes: 3 additions & 1 deletion prql-compiler/prqlc/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,12 @@ fn project_path() -> PathBuf {

fn prqlc_command() -> Command {
let mut cmd = Command::new(get_cargo_bin("prqlc"));
// We set this in CI to force color output, but we don't want `prqlc` to
// We set `CLICOLOR_FORCE` in CI to force color output, but we don't want `prqlc` to
// output color for our snapshot tests. And it seems to override the
// `--color=never` flag.
cmd.env_remove("CLICOLOR_FORCE");
// We don't want the tests to be affected by the user's `RUST_BACKTRACE` setting.
cmd.env_remove("RUST_BACKTRACE");
max-sixty marked this conversation as resolved.
Show resolved Hide resolved
cmd.args(["--color=never"]);
cmd
}