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 Unwrap method to allow to detect root cause error with errors.Is #98

Merged
merged 3 commits into from
Jan 20, 2025

Conversation

C-Pro
Copy link
Contributor

@C-Pro C-Pro commented Jan 20, 2025

We realised that detecting certain types of errors does not work as expected because error types are missing Unwrap method required for errors.Is to work:

	sub.OnError(func(e centrifuge.SubscriptionErrorEvent) {
		if errors.Is(e.Error, centrifuge.ErrUnauthorized) {
			// We never got here, even though Unauthorized error is logged.
		}
		log.Error(e.Error)
	})

This PR adds corresponding methods to error types in errors.go and a corresponding test (fails without Unwrap, but works with it in place). I suspect it may be not required for some types like ConfigError, but adding the method anyway for uniformity.

Also changed a --client_insecure to --client.insecure in the workflow as old flag no longer works with latest centrifuge (this leads to workflows failing).

@C-Pro
Copy link
Contributor Author

C-Pro commented Jan 20, 2025

Actually there's a workaround: since Err field is exported we can do this:

	sub.OnError(func(e centrifuge.SubscriptionErrorEvent) {
		if subSubError, ok := ev.Error.(centrifuge.SubscriptionSubscribeError); ok {
			if errors.Is(subSubError.Err, centrifuge.Timeout) {
				// do something
			}
		}
		log.Error(e.Error)
	})

But I think directly using errors.Is on the returned error is nicer.

@FZambia
Copy link
Member

FZambia commented Jan 20, 2025

Great! Many thanks for the improvement and CI fix

@FZambia FZambia merged commit 757a14b into centrifugal:master Jan 20, 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.

2 participants