MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / verify_org_exists

Function verify_org_exists

atomic-cli/src/commands/org/set.rs:136–157  ·  view source on GitHub ↗

Confirm the slug resolves to an org on the server. Returns a [`CliError::InvalidArgument`] with a clean, slug-specific message on 404 so the user sees the actual problem (typo) rather than a raw HTTP response. Other failures (network, auth) bubble up so the user can distinguish "wrong slug" from "server unreachable".

(slug: &str)

Source from the content-addressed store, hash-verified

134/// a raw HTTP response. Other failures (network, auth) bubble up so the
135/// user can distinguish "wrong slug" from "server unreachable".
136fn verify_org_exists(slug: &str) -> CliResult<()> {
137 let rt = tokio::runtime::Runtime::new()
138 .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to create async runtime: {e}")))?;
139
140 rt.block_on(async {
141 let (client, _resolved) = build_client_with_org(Some(slug), None).await?;
142 match atomic_teams::org::get_org(&client, slug).await {
143 Ok(_) => Ok(()),
144 Err(e) if is_org_not_found(&e) => Err(CliError::InvalidArgument {
145 message: format!(
146 "Organization '{slug}' not found on the server.\n \
147 Check the slug with: atomic org list\n \
148 Or pass --no-verify to set the value without checking."
149 ),
150 }),
151 Err(e) => Err(CliError::RemoteError {
152 message: e.to_string(),
153 url: None,
154 }),
155 }
156 })
157}
158
159fn is_org_not_found(err: &atomic_teams::TeamsError) -> bool {
160 matches!(err, atomic_teams::TeamsError::OrgNotFound(_))

Callers

nothing calls this directly

Calls 3

build_client_with_orgFunction · 0.85
get_orgFunction · 0.85
is_org_not_foundFunction · 0.85

Tested by

no test coverage detected