Skip to content

Commit d8ca95b

Browse files
authored
feat(mobile-app): Make missing path not panic (#2583)
Updates the mobile-app upload command to no longer panic upon a missing path argument, rather log an error and exit gracefully. Adds a test to validate this behavior.
1 parent 05df700 commit d8ca95b

4 files changed

Lines changed: 31 additions & 13 deletions

File tree

src/commands/mobile_app/upload.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ pub fn make_command(command: Command) -> Command {
3434
.value_name("PATH")
3535
.help("The path to the mobile app files to upload. Supported files include Apk, Aab or XCArchive.")
3636
.num_args(1..)
37-
.action(ArgAction::Append),
37+
.action(ArgAction::Append)
38+
.required(true),
3839
)
3940
.arg(
4041
Arg::new("sha")
@@ -49,9 +50,12 @@ pub fn make_command(command: Command) -> Command {
4950
}
5051

5152
pub fn execute(matches: &ArgMatches) -> Result<()> {
52-
let path_strings = matches
53-
.get_many::<String>("paths")
54-
.expect("paths argument is required");
53+
let path_strings: Vec<_> = match matches.get_many::<String>("paths") {
54+
Some(paths) => paths.collect(),
55+
None => {
56+
return Err(anyhow!("clap error: paths argument is required"));
57+
}
58+
};
5559

5660
let sha = matches
5761
.get_one("sha")
@@ -301,14 +305,12 @@ fn upload_file(
301305
build_configuration.unwrap_or("unknown")
302306
);
303307

304-
let chunk_upload_options = api
305-
.get_chunk_upload_options(org)?
306-
.ok_or_else(|| {
307-
anyhow!(
308-
"The Sentry server lacks chunked uploading support, which \
308+
let chunk_upload_options = api.get_chunk_upload_options(org)?.ok_or_else(|| {
309+
anyhow!(
310+
"The Sentry server lacks chunked uploading support, which \
309311
is required for mobile app uploads. {SELF_HOSTED_ERROR_HINT}"
310-
)
311-
})?;
312+
)
313+
})?;
312314

313315
if !chunk_upload_options.supports(ChunkUploadCapability::PreprodArtifacts) {
314316
bail!(

tests/integration/_cases/mobile_app/mobile_app-upload-help.trycmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ $ sentry-cli mobile-app upload --help
33
? success
44
[EXPERIMENTAL] Upload mobile app files to a project.
55

6-
Usage: sentry-cli[EXE] mobile-app upload [OPTIONS] [PATH]...
6+
Usage: sentry-cli[EXE] mobile-app upload [OPTIONS] <PATH>...
77

88
Arguments:
9-
[PATH]... The path to the mobile app files to upload. Supported files include Apk, Aab or
9+
<PATH>... The path to the mobile app files to upload. Supported files include Apk, Aab or
1010
XCArchive.
1111

1212
Options:
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
```
2+
$ sentry-cli mobile-app upload
3+
? failed
4+
error: the following required arguments were not provided:
5+
<PATH>...
6+
7+
Usage: sentry-cli[EXE] mobile-app upload <PATH>...
8+
9+
For more information, try '--help'.
10+
11+
```

tests/integration/mobile_app/upload.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ fn command_mobile_app_upload_no_token() {
1414
TestManager::new().register_trycmd_test("mobile_app/mobile_app-upload-apk-no-token.trycmd");
1515
}
1616

17+
#[test]
18+
fn command_mobile_app_upload_no_path() {
19+
TestManager::new().register_trycmd_test("mobile_app/mobile_app-upload-no-path.trycmd");
20+
}
21+
1722
#[test]
1823
fn command_mobile_app_upload_invalid_aab() {
1924
TestManager::new()

0 commit comments

Comments
 (0)