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(errors): Print backtrace when RUST_BACKTRACE=1 #2189

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 2 additions & 4 deletions src/utils/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ pub fn print_error(err: &Error) {
clap_err.exit();
}

eprintln!("{} {}", style("error:").red(), err);
err.chain()
.skip(1)
.for_each(|cause| eprintln!(" {} {}", style("caused by:").dim(), cause));
// Debug style for error includes cause chain and backtrace (if available).
eprintln!("{} {:?}", style("error:").red(), err);

if Config::current_opt().map_or(true, |config| {
config.get_log_level() < log::LevelFilter::Info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ $ sentry-cli debug-files bundle-jvm --output ./file.txt --debug-id D384DC3B-AB2F
> Bundled 2 files for upload
> Bundle ID: [..]-[..]-[..]-[..]-[..]
error: Unable to write source bundle
caused by: [..]

Caused by:
[..]

Add --log-level=[info|debug] or export SENTRY_LOG_LEVEL=[info|debug] to see more output.
Please attach the full debug log to all bug reports.
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/_cases/info/info-no-token-backtrace.trycmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
```
$ RUST_BACKTRACE=1 sentry-cli info
? failed
Sentry Server: https://sentry.io
Default Organization: -
Default Project: -

Authentication Info:
Method: Unauthorized
error: Auth token is required for this request. Please run `sentry-cli login` and try again!

Stack backtrace:
...

Add --log-level=[info|debug] or export SENTRY_LOG_LEVEL=[info|debug] to see more output.
Please attach the full debug log to all bug reports.

```
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
$ sentry-cli releases delete wat-release
? failed
error: API request failed
caused by: sentry reported an error: This release is referenced by active issues and cannot be removed. (http status: 400)

Caused by:
[..]sentry reported an error: This release is referenced by active issues and cannot be removed. (http status: 400)

Add --log-level=[info|debug] or export SENTRY_LOG_LEVEL=[info|debug] to see more output.
Please attach the full debug log to all bug reports.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ $ sentry-cli send-metric increment -n testmetric
? failed
[..]
error: API request failed
caused by: sentry reported an error: internal server error (http status: 500)

Caused by:
[..]sentry reported an error: internal server error (http status: 500)

Add --log-level=[info|debug] or export SENTRY_LOG_LEVEL=[info|debug] to see more output.
Please attach the full debug log to all bug reports.
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ fn command_info_no_token() {
.case("tests/integration/_cases/info/info-no-token.trycmd");
}

#[test]
fn command_info_no_token_backtrace() {
// Special case where we don't want any env variables set, so we don't use `register_task` helper.
TestCases::new()
.env("SENTRY_INTEGRATION_TEST", "1")
.env("RUST_BACKTRACE", "1")
.case("tests/integration/_cases/info/info-no-token-backtrace.trycmd");
}

#[test]
fn command_info_basic() {
let _server = mock_endpoint(
Expand Down
Loading