Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Make errors an enum type #116

Merged
merged 1 commit into from
Apr 4, 2023
Merged

Make errors an enum type #116

merged 1 commit into from
Apr 4, 2023

Conversation

fortuna
Copy link
Contributor

@fortuna fortuna commented Apr 4, 2023

There's a better way to do enums in Go.

The way we do errors in this API is still problematic, but at least this is a bit better.

@fortuna fortuna requested a review from a team as a code owner April 4, 2023 21:17
@fortuna fortuna requested review from jyyi1 and removed request for a team April 4, 2023 21:17
Copy link
Contributor

@jyyi1 jyyi1 left a comment

Choose a reason for hiding this comment

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

I like it. The code LGTM. But I'm thinking of a more standard way of defining custom errors in Go, and how can we leverage standard errors package. For example, syscall.Errno We may refactor it later.

@@ -48,7 +48,7 @@ type reachabilityError struct {
// the current network. Parallelizes the execution of TCP and UDP checks, selects the appropriate
// error code to return accounting for transient network failures.
// Returns an error if an unexpected error ocurrs.
func CheckConnectivity(client *outline.Client) (int, error) {
func CheckConnectivity(client *outline.Client) (neterrors.Error, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can just return error, and use errors.Is to determine whether it is our neterrors.Error object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree!
Using error unwrapping would be much cleaner, but that would break the existing API, so I left it as is for now.

@fortuna fortuna merged commit 3f77a13 into master Apr 4, 2023
@fortuna fortuna deleted the fortuna-errors branch April 4, 2023 22:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants