Skip to content

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

@PraveenUpadhyay

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions