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

style.md#errors - Nesting can be removed in example of Error Types section #200

Open
PraveenUpadhyay opened this issue Nov 10, 2023 · 0 comments

Comments

@PraveenUpadhyay
Copy link

PraveenUpadhyay commented Nov 10, 2023

I feel we can remove the nesting from the code present in "Error Types" section under "Error" Category in Style.md file

From -

// package foo

var ErrCouldNotOpen = errors.New("could not open")

func Open() error {
  return ErrCouldNotOpen
}

// package bar

if err := foo.Open(); err != nil {
  if errors.Is(err, foo.ErrCouldNotOpen) {
    // handle the error
  } else {
    panic("unknown error")
  }
}

To -

// package foo

var ErrCouldNotOpen = errors.New("could not open")

func Open() error {
  return ErrCouldNotOpen
}

// package bar
err := foo.Open();
if errors.Is(err, foo.ErrCouldNotOpen) {
    // handle the error
} else if err!=nil {
    panic("unknown error")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant