Skip to content

Commit

Permalink
Merge pull request #140 from mindvalley/bugfix/handle-permission-erro…
Browse files Browse the repository at this point in the history
…r-for-tui

PXP-604: handle permission error for the TUI
  • Loading branch information
onimsha authored Sep 6, 2023
2 parents 08687f0 + 9441d0b commit a62a231
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cli/src/commands/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct State {
pub builds: Vec<Build>,
pub deployments: Vec<Deployment>,
pub log_entries_hash_map: HashMap<String, LogEntry>,
pub has_log_errors: bool,
pub log_entries_ids: Vec<String>,
// pub log_entries_next_page_token: Option<String>,
pub last_log_entry_timestamp: Option<String>,
Expand Down Expand Up @@ -105,6 +106,7 @@ impl App {
last_log_entry_timestamp: None,
log_entries_hash_map: HashMap::new(),
log_entries_ids: vec![],
has_log_errors: false,

logs_vertical_scroll_state: ScrollbarState::default(),
logs_horizontal_scroll_state: ScrollbarState::default(),
Expand Down
13 changes: 11 additions & 2 deletions cli/src/commands/tui/events/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,24 @@ pub async fn handle_network_event(
)?;
let resource_names = vec![format!("projects/{}", cluster.google_project_id)];

let mut log = fetch_log_entries(
let mut log = match fetch_log_entries(
Some(resource_names.clone()),
Some(500),
Some(filter.clone()),
None,
gcloud_access_token.clone(),
&mut wk_client,
)
.await?;
.await
{
Ok(data) => data,
Err(error) => {
let mut app_ref = app.lock().await;
app_ref.state.has_log_errors = true;
return Err(error);
}
};

let mut next_page_token = log.next_page_token.clone();
update_logs_entries(Arc::clone(&app), log.entries).await;

Expand Down
10 changes: 10 additions & 0 deletions cli/src/commands/tui/ui/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ impl LogsWidget {
.style(Style::default().fg(Color::DarkGray));
frame.render_widget(title, info);

if app.state.has_log_errors {
let loading_widget = Paragraph::new(Text::styled(
"Something went wrong while fetching logs.",
Style::default().fg(Color::White),
))
.block(Block::default().padding(Padding::new(1, 1, 0, 0)));
frame.render_widget(loading_widget, logs_area);
return;
}

// it will show loader only on the first call
if app.state.is_fetching_log_entries {
let loading_widget = Paragraph::new(Text::styled(
Expand Down
1 change: 1 addition & 0 deletions cli/src/commands/tui/ui/namespace_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ impl NamespaceSelectionWidget {
// to re-trigger the polling
app.state.is_fetching_log_entries = true;
app.state.start_polling_log_entries = false;
app.state.has_log_errors = false;
}

app.current_screen = CurrentScreen::Main;
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ pub enum GCloudError {
Io(#[from] ::std::io::Error),
#[error(transparent)]
GoogleLogging2Error(#[from] google_logging2::Error),
#[error(transparent)]
ResponseError(#[from] tonic::Status),
}

// Secret Extractor Error
Expand Down
3 changes: 1 addition & 2 deletions sdk/src/services/gcloud/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ impl GCloudClient {

let response = service
.list_log_entries(Request::new(request))
.await
.unwrap()
.await?
.into_inner();

Ok(LogEntries {
Expand Down

0 comments on commit a62a231

Please sign in to comment.