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 sentinel errors for the limiter package #301

Closed
joeblubaugh opened this issue May 18, 2023 · 2 comments
Closed

Add sentinel errors for the limiter package #301

joeblubaugh opened this issue May 18, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@joeblubaugh
Copy link

The limiter#Limiter returns two kinds of errors from WaitN():

return fmt.Errorf("rate: Wait(n=%d) exceeds limiter's burst %d", n, burst)
return fmt.Errorf("rate: Wait(n=%d) would exceed context deadline", n)

In the case of an HTTP request limit, I would ideally return a 429 Too Many Requests for each, but there are other errors that can be returned, like a context cancellation. It would be convenient to have an error type exposed in the package API that can be used with errors.As/errors.Is to see if the limiter has rejected the request.

@joeblubaugh joeblubaugh added the enhancement New feature or request label May 18, 2023
@pracucci
Copy link
Contributor

Makes sense. Feel free to open a PR about it.

@joeblubaugh
Copy link
Author

When reading this code, I mistakenly navigated in golang.org/x/time/rate and read some of the WaitN implementation there. That's where the errors described above are generated. I think it wouldn't be a great practice for dskit to inspect the contents of those errors in order to return two different sentinel errors. I'll file an issue with that package instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants