Skip to content

Commit

Permalink
Merge pull request #96 from LavaGames/main
Browse files Browse the repository at this point in the history
handle cases where bucket or entry doesn't exist
  • Loading branch information
ripienaar authored Sep 21, 2023
2 parents 270a14b + 9c8689b commit ebe784e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions jetstream/resource_kv_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ func resourceKVBucketRead(d *schema.ResourceData, m any) error {
}
bucket, err := js.KeyValue(name)
if err != nil {
if err == nats.ErrBucketNotFound {
d.SetId("")
return nil
}
return err
}
status, err := bucket.Status()
Expand Down
8 changes: 8 additions & 0 deletions jetstream/resource_kv_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,18 @@ func resourceKVEntryRead(d *schema.ResourceData, m any) error {
}
kv, err := js.KeyValue(bucket)
if err != nil {
if err == nats.ErrBucketNotFound {
d.SetId("")
return nil
}
return err
}
entry, err := kv.Get(key)
if err != nil {
if err == nats.ErrKeyNotFound {
d.SetId("")
return nil
}
return err
}

Expand Down

0 comments on commit ebe784e

Please sign in to comment.