Skip to content

Commit e86c905

Browse files
committed
fix: CLI error hints for wait combinator failures
- Item 1 (preserve request headers across the 401-retry loop): the sync client now delegates entirely to the async client, and the async retry loop on this branch already rebuilds the retried request with its original headers. Kept branch version. - Item 7 (clear Windows readonly attr before rewriting the auth cache): this branch reworked set_file_permissions to a Unix-only 0o600 path with a no-op elsewhere, so no readonly attribute is ever set and the clear_readonly helper is moot. Kept branch version. - Item 33 (safe downcast of the reused ConfirmPopup): this branch already replaced the raw-pointer downcast with Component::as_any_mut() (as a required method returning &mut dyn Any). Kept branch version. - Item 39 (variant-specific color_eyre suggestion for WaitTimeout / WaitFailed / WaitResourceVanished): applied. Adds OpenStackCliError::wait_hint (cli/core/src/error.rs), wired into osc.rs so wait errors surface an actionable hint instead of ApiError's generic transparent Display. Signed-off-by: Artem Goncharov <artem.goncharov@gmail.com>
1 parent f9c2b96 commit e86c905

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

cli/core/src/error.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,26 @@ impl OpenStackCliError {
216216
data,
217217
}
218218
}
219+
220+
/// A short, user-facing hint for errors coming from the SDK's
221+
/// `wait`/`wait_deleted`/`wait_for_status` combinators, distinguishing
222+
/// timeout, failure, and vanished-resource cases instead of leaving
223+
/// them as an opaque, generic API error.
224+
pub fn wait_hint(&self) -> Option<&'static str> {
225+
let Self::OpenStackApi { source } = self else {
226+
return None;
227+
};
228+
match source {
229+
openstack_sdk_core::api::ApiError::WaitTimeout { .. } => Some(
230+
"the resource may still be transitioning; re-run the command later or check its current status directly",
231+
),
232+
openstack_sdk_core::api::ApiError::WaitFailed { .. } => Some(
233+
"the resource reported a failure state while waiting for it; inspect it directly for details",
234+
),
235+
openstack_sdk_core::api::ApiError::WaitResourceVanished => Some(
236+
"the resource disappeared while waiting for it to reach the desired state (it may have been deleted concurrently)",
237+
),
238+
_ => None,
239+
}
240+
}
219241
}

openstack_cli/src/bin/osc.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use clap_complete::CompleteEnv;
2222
use color_eyre::eyre::{Report, Result};
2323
use color_eyre::owo_colors::OwoColorize;
2424
use color_eyre::section::PanicMessage;
25+
use color_eyre::Help;
2526
use std::env;
2627
use std::fmt;
2728

@@ -37,7 +38,14 @@ async fn main() -> Result<(), Report> {
3738
return Ok(());
3839
}
3940
Ok(false) | Err(_) => {
40-
openstack_cli::entry_point().await?;
41+
if let Err(e) = openstack_cli::entry_point().await {
42+
let hint = e.wait_hint();
43+
let report: Report = e.into();
44+
return Err(match hint {
45+
Some(hint) => report.suggestion(hint),
46+
None => report,
47+
});
48+
}
4149
}
4250
}
4351

0 commit comments

Comments
 (0)