Skip to content

Commit

Permalink
feat: Add global, hidden allow-failure flag and `SENTRY_ALLOW_FAILU…
Browse files Browse the repository at this point in the history
…RE` variable (#1343)

This enables users having cli as part of their build process (mainly mobile app/sdks) to proceed in the rare times when sentry.io is down.
  • Loading branch information
krystofwoldrich authored Oct 4, 2022
1 parent 42345d0 commit b1ce40f
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ fn app() -> Command<'static> {
.global(true)
.help("Do not print any output while preserving correct exit code. This flag is currently implemented only for selected subcommands."),
)
.arg(
Arg::new("allow_failure")
.long("allow-failure")
.global(true)
.hide(true)
.help("Always return 0 exit code."),
)
}

fn add_commands(mut app: Command) -> Command {
Expand Down Expand Up @@ -247,7 +254,18 @@ pub fn execute() -> Result<()> {
.join(" ")
);

run_command(&matches)
match run_command(&matches) {
Ok(()) => Ok(()),
Err(e) => {
if Config::current().get_allow_failure(&matches) {
print_error(&e);
eprintln!("\nCommand failed, however, \"SENTRY_ALLOW_FAILURE\" variable or \"allow-failure\" flag was set. Exiting with 0 exit code.");
Ok(())
} else {
Err(e)
}
}
}
}

fn setup() {
Expand Down
9 changes: 9 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,15 @@ impl Config {
false
}
}

pub fn get_allow_failure(&self, matches: &ArgMatches) -> bool {
matches.is_present("allow_failure")
|| if let Ok(var) = env::var("SENTRY_ALLOW_FAILURE") {
&var == "1" || &var == "true"
} else {
false
}
}
}

fn find_global_config_file() -> Result<PathBuf> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```
$ SENTRY_ALLOW_FAILURE=1 sentry-cli debug-files check non-existing-file-path
? success
error: The system cannot find the file specified. (os error 2)

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.

Command failed, however, "SENTRY_ALLOW_FAILURE" variable or "allow-failure" flag was set. Exiting with 0 exit code.

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```
$ SENTRY_ALLOW_FAILURE=1 sentry-cli debug-files check non-existing-file-path
? success
error: No such file or directory (os error 2)

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.

Command failed, however, "SENTRY_ALLOW_FAILURE" variable or "allow-failure" flag was set. Exiting with 0 exit code.

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```
$ sentry-cli debug-files check non-existing-file-path --allow-failure
? success
error: The system cannot find the file specified. (os error 2)

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.

Command failed, however, "SENTRY_ALLOW_FAILURE" variable or "allow-failure" flag was set. Exiting with 0 exit code.

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```
$ sentry-cli debug-files check non-existing-file-path --allow-failure
? success
error: No such file or directory (os error 2)

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.

Command failed, however, "SENTRY_ALLOW_FAILURE" variable or "allow-failure" flag was set. Exiting with 0 exit code.

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
```
$ sentry-cli debug-files check non-existing-file-path
? failed
error: The system cannot find the file specified. (os error 2)

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
@@ -0,0 +1,9 @@
```
$ sentry-cli debug-files check non-existing-file-path
? failed
error: No such file or directory (os error 2)

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.

```
24 changes: 24 additions & 0 deletions tests/integration/debug_files/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,27 @@ use crate::integration::register_test;
fn command_debug_files_check() {
register_test("debug_files/debug_files-check.trycmd");
}

#[test]
fn command_debug_files_check_no_file() {
#[cfg(not(windows))]
register_test("debug_files/debug_files-check-no-file.trycmd");
#[cfg(windows)]
register_test("debug_files/debug_files-check-no-file-windows.trycmd");
}

#[test]
fn command_debug_files_check_no_file_allow_failure() {
#[cfg(not(windows))]
register_test("debug_files/debug_files-check-no-file-allow-failure.trycmd");
#[cfg(windows)]
register_test("debug_files/debug_files-check-no-file-allow-failure-windows.trycmd");
}

#[test]
fn command_debug_files_check_no_file_allow_failure_env() {
#[cfg(not(windows))]
register_test("debug_files/debug_files-check-no-file-allow-failure-env.trycmd");
#[cfg(windows)]
register_test("debug_files/debug_files-check-no-file-allow-failure-env-windows.trycmd");
}

0 comments on commit b1ce40f

Please sign in to comment.