summaryrefslogtreecommitdiffstats
path: root/lua/conform/init.lua
diff options
context:
space:
mode:
authorSteven Arcangeli <stevearc@stevearc.com>2023-10-02 09:28:05 -0700
committerSteven Arcangeli <stevearc@stevearc.com>2023-10-02 09:28:05 -0700
commitf7b82fb395a4cd636a26ee879b5fd7690612e5a9 (patch)
treea8febfda3c5b45c0d7983d2a82a429170ee8baf1 /lua/conform/init.lua
parent45e0a5096bc5128d18131e5db6f458b8b65adc0a (diff)
fix: error handling for injected formatter
Diffstat (limited to 'lua/conform/init.lua')
-rw-r--r--lua/conform/init.lua9
1 files changed, 4 insertions, 5 deletions
diff --git a/lua/conform/init.lua b/lua/conform/init.lua
index 126e5a7..b72b28f 100644
--- a/lua/conform/init.lua
+++ b/lua/conform/init.lua
@@ -433,8 +433,8 @@ end
--- bufnr nil|integer use this as the working buffer (default 0)
--- async nil|boolean If true the method won't block. Defaults to false. If the buffer is modified before the formatter completes, the formatting will be discarded.
--- quiet nil|boolean Don't show any notifications for warnings or failures. Defaults to false.
----@param callback? fun(err: nil|string, lines: nil|string[]) Called once formatting has completed
----@return nil|string error Only present if async = false
+---@param callback? fun(err: nil|conform.Error, lines: nil|string[]) Called once formatting has completed
+---@return nil|conform.Error error Only present if async = false
---@return nil|string[] new_lines Only present if async = false
M.format_lines = function(formatter_names, lines, opts, callback)
---@type {timeout_ms: integer, bufnr: integer, async: boolean, quiet: boolean}
@@ -460,8 +460,7 @@ M.format_lines = function(formatter_names, lines, opts, callback)
local level = runner.level_for_code(err.code)
log.log(level, err.message)
end
- local err_message = err and err.message
- callback(err_message, new_lines)
+ callback(err, new_lines)
end
if opts.async then
@@ -470,7 +469,7 @@ M.format_lines = function(formatter_names, lines, opts, callback)
local err, new_lines =
runner.format_lines_sync(opts.bufnr, formatters, opts.timeout_ms, nil, lines)
handle_err(err, new_lines)
- return err and err.message, new_lines
+ return err, new_lines
end
end