From 110d8023aff5d903d5413b7bc2e22556cd7b922a Mon Sep 17 00:00:00 2001 From: Mackenzie McDaniel Date: Tue, 29 Sep 2026 16:48:44 -0400 Subject: [PATCH] Check for nil value before `:match`ing it --- lua/flutter-tools/commands.lua | 3 ++- tests/commands_spec.lua | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) 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")