From f3bc1ab3ed11c8c1e09b487fc17c44469024d8aa Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Tue, 18 Feb 2025 19:09:45 +0100 Subject: [PATCH 1/2] Improve error for init with invalid org 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. --- cli/src/commands/init.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cli/src/commands/init.rs b/cli/src/commands/init.rs index 53da76457..52bd378ca 100644 --- a/cli/src/commands/init.rs +++ b/cli/src/commands/init.rs @@ -15,7 +15,7 @@ use reqwest::StatusCode; use crate::api::{PhylumApi, PhylumApiError, ResponseError}; use crate::commands::{project, CommandResult, ExitCode}; use crate::config::{self, Config}; -use crate::{print_user_success, print_user_warning}; +use crate::{print_user_failure, print_user_success, print_user_warning}; /// Handle `phylum init` subcommand. 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) let org = config.org(); let groups: Vec<_> = match org { Some(org) => { - api.org_groups(org).await?.groups.into_iter().map(|group| group.name).collect() + let org_groups = match api.org_groups(org).await { + Ok(org_groups) => org_groups, + Err(err) if err.status() == Some(StatusCode::NOT_FOUND) => { + print_user_failure!("Organization {org:?} does not exist."); + return Ok(ExitCode::NotFound); + }, + Err(err) => return Err(err.into()), + }; + org_groups.groups.into_iter().map(|group| group.name).collect() }, None => { api.get_groups_list().await?.groups.into_iter().map(|group| group.group_name).collect() From 8c393bfcacc1b8ab9d55ff4c468c1b6a2f96726e Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Tue, 18 Feb 2025 19:41:11 +0100 Subject: [PATCH 2/2] Add changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0035eb2e..d66bd4b3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## Unreleased +### Fixed + +- Unclear error when running `phylum init` with an invalid organization + ## 7.3.0 - 2024-12-20 ### Added