Closed bokunodev closed 1 year ago
also would be nice to fix error messages to have first lowercase letter (as per go recommendations)
Thanks for bringing this up! 👍 are you looking specifically for the rules the have assertable error messages? Or would it also be useful to export some of the errors from errors.go?
My request is to have sentinel error type, so that we can check if error come from paseto-go
, regardless of the message.
type TokenError struct{
e error
}
func (te *TokenError) Error() string {
return te.e.Error()
}
func (te *TokenError) Is(e error) bool {
_,ok:=e.(*TokenError)
return ok
}
func (te *TokenError) Unwrap() error {
return te.e
}
To use it
var e error
if errors.Is(e, (*paseto.TokenError) {
log.Fatal("invalid token")
}
log.Fatal("some other fatal error")
But there is 2 PR still on process. This request will break both of them. So I wait instead of submitting a PR.
No need to wait for those PRs if you'd like to open one, they can always be rebased 🙂
I'll try to find some time to get this out soon
My use case would probably be to be able to easy recognize such cases:
That makes complete sense. Once I've got something up, can I tag you both to take a look to make sure it's fitting your desired use cases? 🙂
Sure
Though, Now, I doubt my request. Such a feature can be implemented in user code. Implementing it in the library means I'm stuck with one lib. But the same thing can be said for named errors.
I've opened https://github.com/aidantwoods/go-paseto/pull/12 to address this 🙂
I'd appreciate a review at your leisure to make sure that this is going to catch things you're interested in. I've intentionally left some things as generic errors (like failing to construct a key), since I'm not sure that use case really warrants a custom type (only one thing can really go wrong when calling into those functions).
Looks good for my use case
Now available on latest release v1.2.0
! 😄
probably something insignificant and can be done by user. but, having errors that you can assert would be great.