iferr

command module
v0.0.0-...-fc3ca67 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2017 License: MIT Imports: 8 Imported by: 0

README

iferr

Context-dependent error handling editor plugin for Go

vim demo

Examples

Returns the error value in the correct position, with zero values for other arguments:

func t2() error {
	if err != nil {
		return err
	}
}

func t3() (string, string, error) {
	if err != nil {
		return "", "", err
	}
}

When there's no error value to return, it uses log.Fatal(err):

func main() {
	if err != nil {
		log.Fatal(err)
	}
}

func t1() (string, string) {
	if err != nil {
		log.Fatal(err)
	}

}

Installation and editor integration

The command can be installed in the usual fashion:

go get github.com/TrustRevoked/iferr

You can then pass it a Go file and a byte position to generate the appropriate error handling:

% iferr /path/to/file.go 123
if err != nil {
return "", nil, err
}
vim integration
function GoIfErr()
  let path = '/tmp/goiferr.txt'
  let position = line2byte(line('.'))+col('.')
  execute 'write!' path
  return system('iferr '.shellescape(path).' '.shellescape(position))
endfunction

inoremap <C-E> <C-R>=GoIfErr()<CR>

Then type Ctrl+E in insert mode to add the appropriate error handling code.

License

MIT

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL