chore(tli): replace unwrap/expect with safe alternatives in CLI commands and dashboard
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -225,10 +225,9 @@ pub async fn handle_allocate_portfolio(
|
||||
|
||||
// Add JWT token to metadata
|
||||
let mut request = Request::new(request);
|
||||
request.metadata_mut().insert(
|
||||
"authorization",
|
||||
format!("Bearer {}", jwt_token).parse().unwrap(),
|
||||
);
|
||||
if let Ok(auth_value) = format!("Bearer {}", jwt_token).parse() {
|
||||
request.metadata_mut().insert("authorization", auth_value);
|
||||
}
|
||||
|
||||
// Call AllocatePortfolio RPC
|
||||
let response = client
|
||||
@@ -307,6 +306,7 @@ pub async fn execute_agent_command(
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[allow(clippy::unwrap_used, clippy::expect_used)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
|
||||
@@ -85,9 +85,15 @@ async fn execute_login(
|
||||
return execute_interactive_login(api_gateway_url).await;
|
||||
}
|
||||
|
||||
// Non-interactive login
|
||||
let username = username.unwrap();
|
||||
let _password = password.unwrap(); // Will be used when real login is implemented
|
||||
// Non-interactive login - both are Some() since we checked is_none() above
|
||||
let username = match username {
|
||||
Some(u) => u,
|
||||
None => return execute_interactive_login(api_gateway_url).await,
|
||||
};
|
||||
let _password = match password {
|
||||
Some(p) => p,
|
||||
None => return execute_interactive_login(api_gateway_url).await,
|
||||
};
|
||||
|
||||
println!("{}", "Connecting to API Gateway...".cyan());
|
||||
|
||||
@@ -111,7 +117,7 @@ async fn execute_login(
|
||||
|
||||
let now = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.unwrap_or_default()
|
||||
.as_secs();
|
||||
|
||||
let token_info = TokenInfo {
|
||||
|
||||
@@ -353,11 +353,7 @@ impl TradeMlArgs {
|
||||
|
||||
let confidence = vote.confidence;
|
||||
|
||||
let model_display = if model.is_some() {
|
||||
model.unwrap().to_owned()
|
||||
} else {
|
||||
"Ensemble".to_owned()
|
||||
};
|
||||
let model_display = model.unwrap_or("Ensemble").to_owned();
|
||||
|
||||
Ok((predicted_action, confidence, model_display))
|
||||
}
|
||||
@@ -1290,6 +1286,7 @@ pub fn format_ml_performance(response: &GetMLPerformanceResponse) {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[allow(clippy::unwrap_used, clippy::expect_used)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
|
||||
@@ -306,7 +306,7 @@ impl DashboardManager {
|
||||
.map(|dt| format!(
|
||||
"[{}]{}",
|
||||
dt.shortcut_key().to_uppercase(),
|
||||
dt.title().chars().next().unwrap()
|
||||
dt.title().chars().next().unwrap_or(' ')
|
||||
))
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ")
|
||||
|
||||
@@ -513,7 +513,7 @@ impl ObservabilityDashboard {
|
||||
duration_us: 45.0 + (rand::random::<f64>() * 100.0),
|
||||
timestamp: std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.unwrap_or_default()
|
||||
.as_nanos() as u64,
|
||||
trace_id: format!("trace_{}", self.update_counter),
|
||||
span_id: format!("span_{}", self.update_counter),
|
||||
@@ -562,6 +562,7 @@ pub fn integrate_observability_dashboard() -> ObservabilityDashboard {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[allow(clippy::unwrap_used, clippy::expect_used)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
|
||||
@@ -476,9 +476,9 @@ impl EventAggregator {
|
||||
let event_time = event.timestamp_utc();
|
||||
let window_start = event_time
|
||||
.with_second(0)
|
||||
.unwrap()
|
||||
.unwrap_or(event_time)
|
||||
.with_nanosecond(0)
|
||||
.unwrap();
|
||||
.unwrap_or(event_time);
|
||||
|
||||
// Find or create appropriate window
|
||||
let mut found_window = false;
|
||||
@@ -856,6 +856,7 @@ impl Clone for EventAggregator {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[allow(clippy::unwrap_used, clippy::expect_used)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
|
||||
@@ -358,7 +358,7 @@ async fn validate_token_expiry(token: &str) -> Result<()> {
|
||||
|
||||
let now = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.unwrap_or_default()
|
||||
.as_secs();
|
||||
|
||||
if token_data.claims.exp <= now + 60 {
|
||||
@@ -400,7 +400,9 @@ async fn main() -> Result<()> {
|
||||
// Initialize tracing with configured log level
|
||||
let subscriber = FmtSubscriber::builder().with_max_level(log_level).finish();
|
||||
|
||||
tracing::subscriber::set_global_default(subscriber).expect("Setting default subscriber failed");
|
||||
if let Err(e) = tracing::subscriber::set_global_default(subscriber) {
|
||||
eprintln!("Warning: Failed to set global tracing subscriber: {}", e);
|
||||
}
|
||||
|
||||
// Route commands before launching dashboard
|
||||
match cli.command {
|
||||
@@ -499,6 +501,7 @@ async fn main() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
#[cfg(test)]
|
||||
#[allow(clippy::unwrap_used, clippy::expect_used)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
|
||||
@@ -300,15 +300,16 @@ impl Widget for RiskGauge {
|
||||
let inner = block.inner(area);
|
||||
block.render(area, buf);
|
||||
|
||||
if !self.has_data() {
|
||||
let no_data = ratatui::widgets::Paragraph::new("No risk data")
|
||||
.style(Style::default().fg(self.colors.text))
|
||||
.alignment(Alignment::Center);
|
||||
no_data.render(inner, buf);
|
||||
return;
|
||||
}
|
||||
|
||||
let metrics = self.metrics.as_ref().unwrap();
|
||||
let metrics = match self.metrics.as_ref() {
|
||||
Some(m) => m,
|
||||
None => {
|
||||
let no_data = ratatui::widgets::Paragraph::new("No risk data")
|
||||
.style(Style::default().fg(self.colors.text))
|
||||
.alignment(Alignment::Center);
|
||||
no_data.render(inner, buf);
|
||||
return;
|
||||
},
|
||||
};
|
||||
|
||||
// Status summary area
|
||||
let status_area = Rect {
|
||||
@@ -371,6 +372,7 @@ impl Widget for RiskGauge {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[allow(clippy::unwrap_used, clippy::expect_used)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user