Skip to content

add error handling for when there is nothing#33

Merged
hensur merged 1 commit intomittwald:masterfrom
nofeldt:add-error-handling
Aug 21, 2025
Merged

add error handling for when there is nothing#33
hensur merged 1 commit intomittwald:masterfrom
nofeldt:add-error-handling

Conversation

@nofeldt
Copy link
Copy Markdown
Contributor

@nofeldt nofeldt commented Aug 8, 2025

when vault trys to access an element that is not availabe yet, vault returns an error. vault should return nil because no element is found.

@nofeldt nofeldt force-pushed the add-error-handling branch 2 times, most recently from 2604add to 9675d7e Compare August 8, 2025 08:36
Comment thread kv_v1.go Outdated
if errors.As(err, &resErr) {
if resErr.StatusCode == http.StatusNotFound {
if strings.Contains(err.Error(), "request failed") {
return nil
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should never map an error which results in a nil data return to nil. This would suggest to the user that the request has succeeded, while we return an empty response.

We should use a custom error type which suggest that this is a NotFound error (or an issuer not found error in the latter case)

ErrEncKeyNotFound = errors.New("encryption key not found")

@nofeldt nofeldt force-pushed the add-error-handling branch from 9675d7e to e56ce30 Compare August 19, 2025 12:48
Comment thread kv_v1.go Outdated
return nil
}

func (k *KVv1) mapError(err error) error {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

On second thought (I just noticed this affects the KV Engine), why would we need to map a StatusNotFound error to anything else? Besides breaking the existing API, mapping to a completely unrelated error doesn't seem useful. I think this should be kept as is, any consumer can check the StatusCode already?

@nofeldt nofeldt force-pushed the add-error-handling branch from e56ce30 to 1bb9ce7 Compare August 20, 2025 08:17
@hensur hensur merged commit dfba0dc into mittwald:master Aug 21, 2025
3 checks passed
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.

3 participants