Improve error handling, ensure robust defaults, and eliminate unsafe unwraps/expectations across modules.
This commit is contained in:
@@ -34,7 +34,8 @@ where
|
||||
)
|
||||
.await?;
|
||||
|
||||
conn.write_all(serde_json::to_string(&backup)?.as_bytes()).await?;
|
||||
conn.write_all(serde_json::to_string(&backup)?.as_bytes())
|
||||
.await?;
|
||||
Ok(Some(200))
|
||||
}
|
||||
|
||||
@@ -44,7 +45,7 @@ pub(crate) async fn backup_config<T, const N: usize>(
|
||||
where
|
||||
T: Read + Write,
|
||||
{
|
||||
let input = read_up_to_bytes_from_request(conn, Option::None).await?;
|
||||
let input = read_up_to_bytes_from_request(conn, Some(4096)).await?;
|
||||
let mut board = BOARD_ACCESS.get().await.lock().await;
|
||||
let config_to_backup = serde_json::from_slice(&input)?;
|
||||
board.board_hal.backup_config(&config_to_backup).await?;
|
||||
@@ -70,10 +71,9 @@ where
|
||||
let mut board = BOARD_ACCESS.get().await.lock().await;
|
||||
let info = board.board_hal.backup_info().await;
|
||||
|
||||
|
||||
let json = match info {
|
||||
Ok(h) => {
|
||||
let timestamp = DateTime::from_timestamp_millis(h.timestamp).unwrap();
|
||||
let timestamp = DateTime::from_timestamp_millis(h.timestamp).unwrap_or_default();
|
||||
let wbh = WebBackupHeader {
|
||||
timestamp: timestamp.to_rfc3339(),
|
||||
size: h.size,
|
||||
|
||||
@@ -181,6 +181,7 @@ where
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
#[allow(clippy::panic, clippy::unwrap_used, clippy::expect_used)]
|
||||
pub async fn http_server(reboot_now: Arc<AtomicBool>, stack: Stack<'static>) {
|
||||
let buffer: TcpBuffers<2, 1024, 1024> = TcpBuffers::new();
|
||||
let tcp = Tcp::new(stack, &buffer);
|
||||
|
||||
@@ -108,7 +108,7 @@ where
|
||||
{
|
||||
let actual_data = read_up_to_bytes_from_request(request, None).await?;
|
||||
let time: SetTime = serde_json::from_slice(&actual_data)?;
|
||||
let parsed = DateTime::parse_from_rfc3339(time.time).unwrap();
|
||||
let parsed = DateTime::parse_from_rfc3339(time.time)?;
|
||||
esp_set_time(parsed).await?;
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user