···272272------------------------------------------------------------------------------
273273 *gopher.nvim-iferr*
274274275275-`iferr` provides a way to way to automatically insert `if err != nil` check.
276276-If you want to change `-message` option of `iferr` tool, see |gopher.nvim-config|
275275+`iferr` provides a way to automatically insert `if err != nil` check.
276276+To configure a default `-message` option for the `iferr` tool, see |gopher.nvim-config|
277277278278Usage ~
279279-Execute `:GoIfErr` near any `err` variable to insert the check
279279+280280+1. Insert error check:
281281+ - Place your cursor near any `err` variable
282282+ - Run `:GoIfErr`
283283+284284+2. Insert error check with custom `-message`:
285285+ - Place your cursor near any`err` variable
286286+ - Run `:GoIfErr fmt.Errorf("failed to %w", err)`
287287+288288+Example:
289289+>go
290290+ func test() error {
291291+ err := doSomething()
292292+ // ^ put your cursor here
293293+ // run `:GoIfErr` or `:GoIfErr log.Printf("error: %v", err)`
294294+ }
295295+296296+------------------------------------------------------------------------------
297297+ *iferr.iferr()*
298298+ `iferr.iferr`({message})
299299+Parameters ~
300300+{message} `(optional)` `(string)` Optional custom error message to use instead of config default
280301281302282303==============================================================================
+24-6
lua/gopher/iferr.lua
···33---@toc_entry Iferr
44---@tag gopher.nvim-iferr
55---@text
66---- `iferr` provides a way to way to automatically insert `if err != nil` check.
77---- If you want to change `-message` option of `iferr` tool, see |gopher.nvim-config|
66+--- `iferr` provides a way to automatically insert `if err != nil` check.
77+--- To configure a default `-message` option for the `iferr` tool, see |gopher.nvim-config|
88+---
99+---@usage
1010+--- 1. Insert error check:
1111+--- - Place your cursor near any `err` variable
1212+--- - Run `:GoIfErr`
1313+---
1414+--- 2. Insert error check with custom `-message`:
1515+--- - Place your cursor near any`err` variable
1616+--- - Run `:GoIfErr fmt.Errorf("failed to %w", err)`
817---
99----@usage Execute `:GoIfErr` near any `err` variable to insert the check
1818+--- Example:
1919+--- >go
2020+--- func test() error {
2121+--- err := doSomething()
2222+--- // ^ put your cursor here
2323+--- // run `:GoIfErr` or `:GoIfErr log.Printf("error: %v", err)`
2424+--- }
2525+---
10261127local c = require "gopher.config"
1228local u = require "gopher._utils"
···1430local log = require "gopher._utils.log"
1531local iferr = {}
16321717-function iferr.iferr()
3333+---@param message? string Optional custom error message to use instead of config default
3434+function iferr.iferr(message)
1835 local curb = vim.fn.wordcount().cursor_bytes
1936 local pos = vim.fn.getcurpos()[2]
2037 local fpath = vim.fn.expand "%"
21382239 local cmd = { c.commands.iferr, "-pos", curb }
2323- if c.iferr.message ~= nil and type(c.iferr.message) == "string" then
4040+ local msg = message or c.iferr.message
4141+ if msg ~= nil and type(msg) == "string" then
2442 table.insert(cmd, "-message")
2525- table.insert(cmd, c.iferr.message)
4343+ table.insert(cmd, msg)
2644 end
27452846 local rs = r.sync(cmd, {