From a68355145c6fbc458a33c95e61f255e43e327de9 Mon Sep 17 00:00:00 2001 From: Andrew Kwon Date: Wed, 21 Jul 2021 22:50:57 -0700 Subject: [PATCH] Guard against invalid log messages Resolves #28 --- lua/lib/log.lua | 2 +- lua/presence/init.lua | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lua/lib/log.lua b/lua/lib/log.lua index dd0ff1d..b7b71e4 100644 --- a/lua/lib/log.lua +++ b/lua/lib/log.lua @@ -21,7 +21,7 @@ for i = 1, #Log.levels do Log[level] = function(self, message) -- Skip if log level is not set or the log is below the configured or default level - if not self.level or self.codes[level] < self.codes[self.level] then + if not self.level or self.codes[level] < self.codes[self.level] or type(message) ~= "string" then return end diff --git a/lua/presence/init.lua b/lua/presence/init.lua index b6da519..fe18665 100644 --- a/lua/presence/init.lua +++ b/lua/presence/init.lua @@ -96,8 +96,7 @@ function Presence:setup(options) or string.format(setup_message_fmt, self.os.name) self.log:debug(setup_message) else - self.log:error(string.format("Unable to detect operating system: %s")) - self.log:debug(vim.inspect(vim.loop.os_uname())) + self.log:error(string.format("Unable to detect operating system: %s", vim.inspect(vim.loop.os_uname()))) end -- Use the default or user-defined client id if provided @@ -231,7 +230,7 @@ function Presence:check_discord_socket(path) return end - self.log:debug(string.format("Checked Discord IPC socket, looks good!")) + self.log:debug("Checked Discord IPC socket, looks good!") end) end @@ -336,7 +335,7 @@ function Presence:authorize(on_done) return end - self.log:info("Authorized with Discord for "..response.data.user.username) + self.log:info(string.format("Authorized with Discord for %s", response.data.user.username)) self.is_authorized = true if on_done then on_done() end @@ -761,7 +760,7 @@ function Presence:update_for_buffer(buffer, should_debounce) self.log:debug("Setting Discord activity...") self.discord:set_activity(activity, function(err) if err then - self.log:error("Failed to set activity in Discord: "..err) + self.log:error(string.format("Failed to set activity in Discord: %s", err)) return end