diff --git a/lua/flutter-tools/commands.lua b/lua/flutter-tools/commands.lua index 9e9a909..bd5814e 100644 --- a/lua/flutter-tools/commands.lua +++ b/lua/flutter-tools/commands.lua @@ -54,8 +54,9 @@ local function set_current_device(device) end ---Resolve the device name from the `Launching ... on in mode` output line ----@param line string +---@param line string|nil 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) }) diff --git a/tests/commands_spec.lua b/tests/commands_spec.lua index 139577b..ed261be 100644 --- a/tests/commands_spec.lua +++ b/tests/commands_spec.lua @@ -110,6 +110,10 @@ 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) + end) + it("should batch consecutive error lines into one notification", function() local config = require("flutter-tools.config") local ui = require("flutter-tools.ui")