Skip to content

Commit c0ccd70

Browse files
authored
Improve error for init with invalid org (#1577)
This adds some error details to `phylum init` when executed with an organization that either doesn't exist, or the user has no access to. Closes #1576.
1 parent 0a6236d commit c0ccd70

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
88

99
## Unreleased
1010

11+
### Fixed
12+
13+
- Unclear error when running `phylum init` with an invalid organization
14+
1115
## 7.3.0 - 2024-12-20
1216

1317
### Added

cli/src/commands/init.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use reqwest::StatusCode;
1515
use crate::api::{PhylumApi, PhylumApiError, ResponseError};
1616
use crate::commands::{project, CommandResult, ExitCode};
1717
use crate::config::{self, Config};
18-
use crate::{print_user_success, print_user_warning};
18+
use crate::{print_user_failure, print_user_success, print_user_warning};
1919

2020
/// Handle `phylum init` subcommand.
2121
pub async fn handle_init(api: &PhylumApi, matches: &ArgMatches, config: Config) -> CommandResult {
@@ -44,7 +44,15 @@ pub async fn handle_init(api: &PhylumApi, matches: &ArgMatches, config: Config)
4444
let org = config.org();
4545
let groups: Vec<_> = match org {
4646
Some(org) => {
47-
api.org_groups(org).await?.groups.into_iter().map(|group| group.name).collect()
47+
let org_groups = match api.org_groups(org).await {
48+
Ok(org_groups) => org_groups,
49+
Err(err) if err.status() == Some(StatusCode::NOT_FOUND) => {
50+
print_user_failure!("Organization {org:?} does not exist.");
51+
return Ok(ExitCode::NotFound);
52+
},
53+
Err(err) => return Err(err.into()),
54+
};
55+
org_groups.groups.into_iter().map(|group| group.name).collect()
4856
},
4957
None => {
5058
api.get_groups_list().await?.groups.into_iter().map(|group| group.group_name).collect()

0 commit comments

Comments
 (0)