Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
bengsparks authored Aug 19, 2024
2 parents bbc3c34 + 17e5d65 commit 4db9f51
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions async-nats/src/jetstream/kv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,10 @@ impl Store {
// Deleted or Purged key, we can create it again.
Some(Entry {
operation: Operation::Delete | Operation::Purge,
revision,
..
}) => {
let revision = self.put(key, value).await?;
let revision = self.update(key, value, revision).await?;
Ok(revision)
}

Expand Down Expand Up @@ -1250,6 +1251,7 @@ impl From<UpdateError> for CreateError {
match error.kind() {
UpdateErrorKind::InvalidKey => Error::from(CreateErrorKind::InvalidKey),
UpdateErrorKind::TimedOut => Error::from(CreateErrorKind::Publish),
UpdateErrorKind::WrongLastRevision => Error::from(CreateErrorKind::AlreadyExists),
UpdateErrorKind::Other => Error::from(CreateErrorKind::Other),
}
}
Expand Down Expand Up @@ -1362,6 +1364,7 @@ crate::from_with_timeout!(WatchError, WatchErrorKind, StreamError, StreamErrorKi
pub enum UpdateErrorKind {
InvalidKey,
TimedOut,
WrongLastRevision,
Other,
}

Expand All @@ -1370,14 +1373,25 @@ impl Display for UpdateErrorKind {
match self {
Self::InvalidKey => write!(f, "key cannot be empty or start/end with `.`"),
Self::TimedOut => write!(f, "timed out"),
Self::WrongLastRevision => write!(f, "wrong last revision"),
Self::Other => write!(f, "failed getting entry"),
}
}
}

pub type UpdateError = Error<UpdateErrorKind>;

crate::from_with_timeout!(UpdateError, UpdateErrorKind, PublishError, PublishErrorKind);
impl From<PublishError> for UpdateError {
fn from(err: PublishError) -> Self {
match err.kind() {
PublishErrorKind::TimedOut => Self::new(UpdateErrorKind::TimedOut),
PublishErrorKind::WrongLastSequence => {
Self::with_source(UpdateErrorKind::WrongLastRevision, err)
}
_ => Self::with_source(UpdateErrorKind::Other, err),
}
}
}

#[derive(Clone, Copy, Debug, PartialEq)]
pub enum WatcherErrorKind {
Expand Down

0 comments on commit 4db9f51

Please sign in to comment.