From 46be656f2b62759b1282545515caaba145dc7d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tautvydas=20S=CC=8Cidlauskas?= Date: Tue, 6 Oct 2026 08:16:19 +0300 Subject: [PATCH] fix(commands): ignore the nil line sent when the run output closes plenary calls on_stdout/on_stderr with nil once the job's output closes, so every run exit delivered nil to on_run_data. --- lua/flutter-tools/commands.lua | 5 +++-- tests/commands_spec.lua | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lua/flutter-tools/commands.lua b/lua/flutter-tools/commands.lua index bd5814e..1e2eb08 100644 --- a/lua/flutter-tools/commands.lua +++ b/lua/flutter-tools/commands.lua @@ -54,9 +54,8 @@ local function set_current_device(device) end ---Resolve the device name from the `Launching ... on in mode` output line ----@param line string|nil +---@param line string local function update_device_from_output(line) - if not line then return end local name = line:match("^Launching .+ on (.+) in %w+ mode") if not name then return end local device = vim.tbl_extend("force", current_device or {}, { name = vim.trim(name) }) @@ -115,7 +114,9 @@ end ---Handle output from flutter run command ---@param is_err boolean if this is stdout or stderr +---@param data string? nil once the job's output stream closes local function on_run_data(is_err, data) + if not data then return end if is_err and config.dev_log.notify_errors then queue_error_notification(data) end update_device_from_output(data) dev_log.log(data) diff --git a/tests/commands_spec.lua b/tests/commands_spec.lua index ed261be..3685bf5 100644 --- a/tests/commands_spec.lua +++ b/tests/commands_spec.lua @@ -110,8 +110,19 @@ describe("commands", function() assert.is_nil(commands.current_device()) end) - it("should not crash when output line is nil", function() - assert.has_no.errors(function() commands.__update_device_from_output(nil) end) + it("should ignore the nil line sent when the run output closes", function() + local config = require("flutter-tools.config") + config.dev_log.notify_errors = true + config.dev_log.filter = function(line) return not line:match("^D/") end + + local ok, err = pcall(function() + commands.__on_run_data(false, nil) + commands.__on_run_data(true, nil) + end) + + config.dev_log.notify_errors = false + config.dev_log.filter = nil + assert.is_true(ok, err) end) it("should batch consecutive error lines into one notification", function()