Skip to content

Files

Latest commit

 Cannot retrieve latest commit at this time.

History

History
69 lines (50 loc) · 918 Bytes

README.md

File metadata and controls

69 lines (50 loc) · 918 Bytes

Generate "if err != nil {" block

Generate if err != nil { block for current function.

Usage

Install and update by

go install github.com/koron/iferr@latest

Run, it get if err != nil { block for the postion at 1234 bytes.

$ iferr -pos 1234 < main.go
if err != nil {
 return ""
}
$ iferr -pos 1234 < main.go
if err != nil {
 return ""
}

Customize your error message:

$ iferr -pos 110 -message 'fmt.Errorf("failed to %w", err)' < main.go
if err != nil {
        return 0, fmt.Errorf("failed to %w", err)
}

Vim plugin

return {
  "lumoping/iferr-vim",
}

Before:

package foo

import "io"

func Foo() (io.Reader, error) { // the cursor on this line.
}

Run :IfErr then you will get:

package foo

import "io"

func Foo() (io.Reader, error) {
 if err != nil {
  return nil, err
 }
} // new cursor is at here.