koron/iferr

Generate "if err != nil {" block

94

stars

21

commits

Go

primary language

Jul 27, 2026

updated

README

Generate "if err != nil {" block

PkgGoDev Actions/Go Ask DeepWiki

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

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

Copy vim/ftplugin/go/iferr.vim as ~/.vim/ftplugin/go/iferr.vim.

It defines :IfErr command for go filetype. It will insert if err != nil { block at next line of the cursor.

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.

Contributors

koron

17 commits

arnevm123

1 commits

Jille

1 commits

mattn

1 commits

koron/iferr

Generate "if err != nil {" block

94

stars

21

commits

Go

primary language

Jul 27, 2026

updated

README

Generate "if err != nil {" block

PkgGoDev Actions/Go Ask DeepWiki

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

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

Copy vim/ftplugin/go/iferr.vim as ~/.vim/ftplugin/go/iferr.vim.

It defines :IfErr command for go filetype. It will insert if err != nil { block at next line of the cursor.

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.

Contributors

koron

17 commits

arnevm123

1 commits

Jille

1 commits

mattn

1 commits

Languages

Go

75.5%

Makefile

19.7%

Vim Script

4.9%