Skip to content
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

- Add `projects` field to `SentryCliUploadSourceMapsOptions` ([#2856](https://github.com/getsentry/sentry-cli/pull/2856))

### Fixes

- Don't use hidden progress bar ([#2830](https://github.com/getsentry/sentry-cli/pull/2830)) by @lcian
- Fixed an issue where log messages would not show up when redirecting stderr to a file and using any subcommand that uses a progress bar, such as `sentry-cli debug-files bundle-jvm` and `sentry-cli sourcemaps upload`.

## 2.56.1

### Deprecations
Expand Down
2 changes: 1 addition & 1 deletion src/commands/debug_files/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn find_ids(
pb.set_message(p);
}
pb.tick();
pb.set_prefix(&format!("{}", found_files.len()));
pb.set_prefix(format!("{}", found_files.len()));

let found: Vec<_> = types
.iter()
Expand Down
2 changes: 1 addition & 1 deletion src/utils/dif_upload/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ fn search_difs(options: &DifUpload) -> Result<Vec<DifMatch<'static>>> {
}
};

pb.set_prefix(&collected.len().to_string());
pb.set_prefix(collected.len().to_string());
Ok(())
})?;
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/file_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl ReleaseFileSearch {
if file.file_type().is_some_and(|t| t.is_dir()) {
continue;
}
pb.set_message(&format!("{}", file.path().display()));
pb.set_message(format!("{}", file.path().display()));

info!("found: {} ({} bytes)", file.path().display(), {
#[expect(clippy::unwrap_used, reason = "legacy code")]
Expand All @@ -164,7 +164,7 @@ impl ReleaseFileSearch {
};
collected.push(file_match);

pb.set_prefix(&collected.len().to_string());
pb.set_prefix(collected.len().to_string());
}

pb.finish_and_clear();
Expand Down
115 changes: 83 additions & 32 deletions src/utils/progress.rs
Original file line number Diff line number Diff line change
@@ -1,76 +1,127 @@
use parking_lot::RwLock;
use std::env;
use std::ops::Deref;
use std::io::IsTerminal as _;
use std::sync::Arc;
use std::time::Instant;

use crate::utils::logging;

pub use indicatif::ProgressStyle;

pub fn is_progress_bar_visible() -> bool {
env::var("SENTRY_NO_PROGRESS_BAR") != Ok("1".into())
/// By default, use the progress bar when we can detect we're running in a terminal.
/// `SENTRY_NO_PROGRESS_BAR` takes precedence and can be used to disable the progress bar
/// regardless of whether or not we're in a terminal.
pub fn use_progress_bar() -> bool {
if env::var("SENTRY_NO_PROGRESS_BAR") == Ok("1".into()) {
return false;
}
std::io::stderr().is_terminal()
}

/// Wrapper that optionally holds a progress bar.
/// If there's a progress bar, forward calls to it.
/// Otherwise, forward messages to `log` calls.
pub struct ProgressBar {
inner: Arc<indicatif::ProgressBar>,
inner: Option<Arc<indicatif::ProgressBar>>,
start: Instant,
}

impl ProgressBar {
pub fn new(len: usize) -> Self {
if is_progress_bar_visible() {
indicatif::ProgressBar::new(len as u64).into()
if use_progress_bar() {
Self::from_indicatif(indicatif::ProgressBar::new(len as u64))
} else {
Self::hidden()
Self::no_progress_bar()
}
}

pub fn new_spinner() -> Self {
if is_progress_bar_visible() {
indicatif::ProgressBar::new_spinner().into()
if use_progress_bar() {
Self::from_indicatif(indicatif::ProgressBar::new_spinner())
} else {
Self::hidden()
Self::no_progress_bar()
}
}

pub fn hidden() -> Self {
indicatif::ProgressBar::hidden().into()
fn from_indicatif(pb: indicatif::ProgressBar) -> Self {
let inner = Arc::new(pb);
logging::set_progress_bar(Some(Arc::downgrade(&inner)));
ProgressBar {
inner: Some(inner),
start: Instant::now(),
}
}

fn no_progress_bar() -> Self {
ProgressBar {
inner: None,
start: Instant::now(),
}
}

pub fn finish_with_duration(&self, op: &str) {
let dur = self.start.elapsed();
// We could use `dur.as_secs_f64()`, but its unnecessarily precise (micros). Millis are enough for our purpose.
let msg = format!("{op} completed in {}s", dur.as_millis() as f64 / 1000.0);
let progress_style = ProgressStyle::default_bar().template("{prefix:.dim} {msg}");
self.inner.set_style(progress_style);
self.inner.set_prefix(">");
self.inner.finish_with_message(&msg);
logging::set_progress_bar(None);

if let Some(inner) = &self.inner {
let progress_style = ProgressStyle::default_bar().template("{prefix:.dim} {msg}");
inner.set_style(progress_style);
inner.set_prefix(">");
inner.finish_with_message(&msg);
logging::set_progress_bar(None);
} else {
eprintln!("> {msg}");
}
}

pub fn finish_and_clear(&self) {
self.inner.finish_and_clear();
logging::set_progress_bar(None);
if let Some(inner) = &self.inner {
inner.finish_and_clear();
logging::set_progress_bar(None);
}
}
}

impl From<indicatif::ProgressBar> for ProgressBar {
fn from(pb: indicatif::ProgressBar) -> Self {
let inner = Arc::new(pb);
logging::set_progress_bar(Some(Arc::downgrade(&inner)));
ProgressBar {
inner,
start: Instant::now(),
pub fn set_style(&self, style: ProgressStyle) {
if let Some(inner) = &self.inner {
inner.set_style(style);
}
}

pub fn set_message<S: AsRef<str>>(&self, msg: S) {
if let Some(inner) = &self.inner {
inner.set_message(msg.as_ref());
}
}

pub fn tick(&self) {
if let Some(inner) = &self.inner {
inner.tick();
}
}
}

impl Deref for ProgressBar {
type Target = indicatif::ProgressBar;
pub fn set_prefix<S: AsRef<str>>(&self, prefix: S) {
if let Some(inner) = &self.inner {
inner.set_prefix(prefix.as_ref());
}
}

pub fn set_position(&self, pos: u64) {
if let Some(inner) = &self.inner {
inner.set_position(pos);
}
}

fn deref(&self) -> &Self::Target {
&self.inner
pub fn inc(&self, delta: u64) {
if let Some(inner) = &self.inner {
inner.inc(delta);
}
}

pub fn enable_steady_tick(&self, interval: u64) {
if let Some(inner) = &self.inner {
inner.enable_steady_tick(interval);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
$ sentry-cli build upload tests/integration/_fixtures/build/apk.apk
? success
WARN [..] EXPERIMENTAL: The build subcommand is experimental. The command is subject to breaking changes and may be removed without notice in any release.
> Preparing for upload completed in [..]
Successfully uploaded 1 file to Sentry
- tests/integration/_fixtures/build/apk.apk (http[..]/wat-org/preprod/wat-project/42)

Expand Down
2 changes: 2 additions & 0 deletions tests/integration/_cases/build/build-upload-apk.trycmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
$ sentry-cli build upload tests/integration/_fixtures/build/apk.apk --head-sha test_head_sha
? success
WARN [..] EXPERIMENTAL: The build subcommand is experimental. The command is subject to breaking changes and may be removed without notice in any release.
> Preparing for upload completed in [..]
> Uploading completed in [..]
Successfully uploaded 1 file to Sentry
- tests/integration/_fixtures/build/apk.apk (http[..]/wat-org/preprod/wat-project/42)

Expand Down
1 change: 1 addition & 0 deletions tests/integration/_cases/build/build-upload-ipa.trycmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
$ sentry-cli build upload tests/integration/_fixtures/build/ipa.ipa --head-sha test_head_sha
? success
WARN [..] EXPERIMENTAL: The build subcommand is experimental. The command is subject to breaking changes and may be removed without notice in any release.
> Preparing for upload completed in [..]
Successfully uploaded 1 file to Sentry
- tests/integration/_fixtures/build/ipa.ipa (http[..]/wat-org/preprod/wat-project/some-text-id)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
$ sentry-cli debug-files bundle-jvm --output . --debug-id 48dee70b-4f3f-4a49-9223-de441738f7cd empty-dir
? success
> Found 0 files
> Bundling completed in [..]
> Bundled 0 files for upload
> Bundle ID: [..]-[..]-[..]-[..]-[..]
Created ./48dee70b-4f3f-4a49-9223-de441738f7cd.zip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
$ sentry-cli debug-files bundle-jvm --output ./file.txt --debug-id D384DC3B-AB2F-4DC7-903D-2C851E27E094 ./io
? failed
> Found 2 files
> Bundling completed in [..]
> Bundled 2 files for upload
> Bundle ID: [..]-[..]-[..]-[..]-[..]
error: Unable to write source bundle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
$ sentry-cli debug-files bundle-jvm --output i-do-not-exist --debug-id 0B693ABA-531C-4EB6-99E4-B7320C3C85DA jvm
? success
> Found 2 files
> Bundling completed in [..]
> Bundled 2 files for upload
> Bundle ID: [..]-[..]-[..]-[..]-[..]
Created i-do-not-exist/0b693aba-531c-4eb6-99e4-b7320c3c85da.zip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
$ sentry-cli debug-files bundle-jvm --output . --debug-id a4368a48-0880-40d7-9a26-c9ef5a84d156 ./io
? success
> Found 2 files
> Bundling completed in [..]
> Bundled 2 files for upload
> Bundle ID: [..]-[..]-[..]-[..]-[..]
Created ./a4368a48-0880-40d7-9a26-c9ef5a84d156.zip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ $ sentry-cli --log-level=debug debug-files upload --include-sources tests/integr
INFO [..] Loaded config from [CWD]/.sentryclirc
...
> Found 1 debug information file (1 with embedded sources)
DEBUG [..] trying to collect sources for SrcGenSampleApp.pdb
DEBUG [..] Trying to add source file: /Users/matt/Code/temp/SrcGenSampleApp/SrcGenSampleApp/Program.cs
DEBUG [..] Trying to add source file: /Users/matt/Code/temp/SrcGenSampleApp/SrcGenSampleApp/obj/Release/net6.0/SrcGenSampleApp.GlobalUsings.g.cs
DEBUG [..] Trying to add source file: /Users/matt/Code/temp/SrcGenSampleApp/SrcGenSampleApp/obj/Release/net6.0/.NETCoreApp,Version=v6.0.AssemblyAttributes.cs
DEBUG [..] Trying to add source file: /Users/matt/Code/temp/SrcGenSampleApp/SrcGenSampleApp/obj/Release/net6.0/SrcGenSampleApp.AssemblyInfo.cs
DEBUG [..] Skipping embedded source file: /Users/matt/Code/temp/SrcGenSampleApp/SrcGenSampleApp/MySourceGenerator/MySourceGenerator.HelloSourceGenerator/Program.g.cs
DEBUG [..] No sources found for SrcGenSampleApp.pdb
> Resolved source code for 0 debug information files
> Prepared debug information file for upload
...
> Nothing to upload, all files are on the server
...

```
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ react-native-xcode.sh called with args:
Using React Native Packager bundle and source map.
Processing react-native sourcemaps for Sentry upload.
> Analyzing 2 sources
> Analyzing completed in [..]
> Rewriting sources
> Rewriting completed in [..]
> Adding source map references
error: Info.plist was not found or an parsing error occurred

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ react-native-xcode.sh called with args:
Using React Native Packager bundle and source map.
Processing react-native sourcemaps for Sentry upload.
> Analyzing 2 sources
> Analyzing completed in [..]
> Rewriting sources
> Rewriting completed in [..]
> Adding source map references
> Bundling completed in [..]
> Bundled 2 files for upload
> Bundle ID: [..]-[..]-[..]-[..]-[..]
> Optimizing completed in [..]
> Uploading completed in [..]
> Uploaded files to Sentry
> Processing completed in [..]
> File upload complete (processing pending on server)
> Organization: wat-org
> Projects: wat-project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ $ sentry-cli releases files wat-release upload-sourcemaps --url-prefix '~/assets
? success
⚠ DEPRECATION NOTICE: This functionality will be removed in a future version of `sentry-cli`. Use the `sourcemaps` command instead.
> Rewriting sources
> Rewriting completed in [..]
> Adding source map references
> Nothing to upload

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ $ sentry-cli sourcemaps inject .
> Searching .
> Found 18 files
> Analyzing 18 sources
> Analyzing completed in [..]
> Injecting debug ids

Source Map Debug ID Injection Report
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ $ sentry-cli sourcemaps inject ./
> Searching ./
> Found 11 files
> Analyzing 11 sources
> Analyzing completed in [..]
> Injecting debug ids

Source Map Debug ID Injection Report
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ $ sentry-cli sourcemaps inject .
> Searching .
> Found 1 file
> Analyzing 1 sources
> Analyzing completed in [..]
> Injecting debug ids

Source Map Debug ID Injection Report
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ $ sentry-cli sourcemaps inject ./server ./static
> Searching ./static
> Found 8 files
> Analyzing 19 sources
> Analyzing completed in [..]
> Injecting debug ids

Source Map Debug ID Injection Report
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ $ sentry-cli sourcemaps inject ./code ./maps ./maps2 --log-level warn
> Searching ./maps2
> Found 1 file
> Analyzing 5 sources
> Analyzing completed in [..]
> Injecting debug ids
WARN [..]-[..]-[..] [..]:[..]:[..].[..] [..]:[..] Ambiguous matches for sourcemap path ./code/foo/index.js.map:
WARN [..]-[..]-[..] [..]:[..]:[..].[..] [..]:[..] ./maps/foo/index.js.map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ $ sentry-cli sourcemaps inject ./code ./maps
> Searching ./maps
> Found 2 files
> Analyzing 4 sources
> Analyzing completed in [..]
> Injecting debug ids

Source Map Debug ID Injection Report
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ $ sentry-cli sourcemaps inject ./server ./static
> Searching ./static
> Found 8 files
> Analyzing 24 sources
> Analyzing completed in [..]
> Injecting debug ids

Source Map Debug ID Injection Report
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ $ sentry-cli sourcemaps upload tests/integration/_fixtures/upload_debugid_alias
? success
> Found 2 files
> Analyzing 2 sources
> Analyzing completed in [..]
> Rewriting sources
> Rewriting completed in [..]
> Adding source map references
> Bundling completed in [..]
> Bundled 2 files for upload
> Bundle ID: [..]-[..]-[..]-[..]-[..]
> Optimizing completed in [..]
> Uploading completed in [..]
> Uploaded files to Sentry
> Processing completed in [..]
> File upload complete (processing pending on server)
> Organization: wat-org
> Projects: wat-project
Expand Down
Loading