1
0
Fork 0
mirror of https://github.com/jiriks74/presence.nvim synced 2024-12-29 19:32:05 +01:00

Guard against invalid log messages

Resolves #28
This commit is contained in:
Andrew Kwon 2021-07-21 22:50:57 -07:00
parent 080d24394b
commit a68355145c
2 changed files with 5 additions and 6 deletions

View file

@ -21,7 +21,7 @@ for i = 1, #Log.levels do
Log[level] = function(self, message) Log[level] = function(self, message)
-- Skip if log level is not set or the log is below the configured or default level -- 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 return
end end

View file

@ -96,8 +96,7 @@ function Presence:setup(options)
or string.format(setup_message_fmt, self.os.name) or string.format(setup_message_fmt, self.os.name)
self.log:debug(setup_message) self.log:debug(setup_message)
else else
self.log:error(string.format("Unable to detect operating system: %s")) self.log:error(string.format("Unable to detect operating system: %s", vim.inspect(vim.loop.os_uname())))
self.log:debug(vim.inspect(vim.loop.os_uname()))
end end
-- Use the default or user-defined client id if provided -- Use the default or user-defined client id if provided
@ -231,7 +230,7 @@ function Presence:check_discord_socket(path)
return return
end end
self.log:debug(string.format("Checked Discord IPC socket, looks good!")) self.log:debug("Checked Discord IPC socket, looks good!")
end) end)
end end
@ -336,7 +335,7 @@ function Presence:authorize(on_done)
return return
end 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 self.is_authorized = true
if on_done then on_done() end 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.log:debug("Setting Discord activity...")
self.discord:set_activity(activity, function(err) self.discord:set_activity(activity, function(err)
if err then 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 return
end end