Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ErrKeyExists that is compatible with errors.Is on kv.Create #1136

Merged
merged 3 commits into from Nov 17, 2022

Conversation

wallyqs
Copy link
Member

@wallyqs wallyqs commented Nov 17, 2022

Follow up from (#1135)
This changes the returned error on kv.Create now to be wrapping the APIError and show error information relevant to the kv.Create API as well:

nats: wrong last sequence: 1: key exists

instead of:

nats: wrong last sequence: 1

The wrapped error makes it possible to make checks like this as well:

_, err = kv.Create("key", []byte("1"))
if !errors.Is(err, ErrKeyExists) { ... }

And also still possible to get the original APIError if needed:

_, err = kv.Create("key", []byte("1"))
var aerr *APIError
if errors.As(err, &aerr) { ... }

Signed-off-by: Waldemar Quevedo wally@nats.io

Signed-off-by: Waldemar Quevedo <wally@nats.io>
kv.go Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Nov 17, 2022

Coverage Status

Coverage decreased (-0.02%) to 85.798% when pulling 5e12137 on js-kv-err into 5044b6e on main.

Signed-off-by: Waldemar Quevedo <wally@nats.io>
Signed-off-by: Waldemar Quevedo <wally@nats.io>
@wallyqs wallyqs marked this pull request as ready for review November 17, 2022 20:01
Copy link
Member

@bruth bruth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks solid to me and retains backwards compatibility except for the, hopefully rare/no longer used practice of, doing if err.Error() == "..." { ... }.

Copy link
Collaborator

@piotrpio piotrpio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wallyqs wallyqs changed the title Add KeyValueError that is compatible with errors.Is on kv.Create Add ErrKeyExists that is compatible with errors.Is on kv.Create Nov 17, 2022
@wallyqs wallyqs merged commit 8499836 into main Nov 17, 2022
@wallyqs wallyqs deleted the js-kv-err branch November 17, 2022 21:33
@piotrpio piotrpio mentioned this pull request Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants