From 7fda5d32735f0865d883d59258e113d5dc1d7193 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Tue, 31 Oct 2017 13:23:12 +0100 Subject: [PATCH] awful.rules: Handle non-existing tags If a tag is specified by name, but no such tags exist, awful.rules would cause an error (attempt to index a nil value). Fix this and add a test for this case. Fixes: https://github.com/awesomeWM/awesome/issues/2087 Signed-off-by: Uli Schlachter --- lib/awful/rules.lua | 6 ++++++ tests/test-awful-rules.lua | 14 +++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/awful/rules.lua b/lib/awful/rules.lua index 10a7bb86d..a3c689251 100644 --- a/lib/awful/rules.lua +++ b/lib/awful/rules.lua @@ -292,7 +292,13 @@ local force_ignore = { function rules.high_priority_properties.tag(c, value, props) if value then if type(value) == "string" then + local name = value value = atag.find_by_name(c.screen, value) + if not value then + require("gears.debug").print_error("awful.rules-rule specified " + .. "tag = '" .. name .. "', but no such tag exists") + return + end end -- In case the tag has been forced to another screen, move the client diff --git a/tests/test-awful-rules.lua b/tests/test-awful-rules.lua index be258fc10..59b1b43f9 100644 --- a/tests/test-awful-rules.lua +++ b/tests/test-awful-rules.lua @@ -5,6 +5,7 @@ local test_client = require("_client") local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1) local callback_called = false +local message_printed = false -- Magic table to store tests local tests = {} @@ -46,9 +47,16 @@ local function get_client_by_class(class) end end +local orig_error = gears.debug.print_error +function gears.debug.print_error(msg) + assert(not message_printed, msg) + assert(msg:find("specified tag = 'does_not_exist', but no such tag exists"), msg) + message_printed = true +end + -- Test callback and floating test_rule { - properties = { floating = true }, + properties = { floating = true, tag = "does_not_exist" }, callback = function(c) assert(type(c) == "client") callback_called = true @@ -57,6 +65,10 @@ test_rule { -- Test if callbacks works assert(callback_called) + -- Test that the "does_not_exist"-tag caused an error + assert(message_printed) + gears.debug.print_error = orig_error + -- Make sure "smart" dynamic properties are applied assert(get_client_by_class(class).floating)