Skip to content

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

Description

@PraveenUpadhyay

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")
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions