Skip to content

Commit

Permalink
Create initial shadow state, if dao read fails during getShadow opera…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
MathiasKoch committed Jul 31, 2024
1 parent c311554 commit f3827b9
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/shadows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,19 @@ where
pub async fn get_shadow(&mut self) -> Result<S, Error> {
let new_desired = self.handler.get_shadow().await?;
debug!("Persisting new state after get shadow request");
let mut state = self.dao.read().await?;
state.apply_patch(new_desired);
self.dao.write(&state).await?;
Ok(state)
match self.dao.read().await {
Ok(mut state) => {
state.apply_patch(new_desired);
self.dao.write(&state).await?;
Ok(state)
}
Err(_) => {
let mut state = S::default();
state.apply_patch(new_desired);
self.dao.write(&state).await?;
Ok(state)
}
}
}

/// Initiate an `UpdateShadow` request, reporting the local state to the cloud.
Expand Down

0 comments on commit f3827b9

Please sign in to comment.