From d5dd0aa1e633691ea6fa9b366b366a0a13cf7eba Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Fri, 8 Oct 2021 12:28:02 -0600 Subject: [PATCH] fix(diagnostic): error on invalid severity value (#15965) Users can pass string values for severities that match with the enum names (e.g. "Warn" or "Info") which are converted to the corresponding numerical value in `to_severity`. Invalid strings were simply left as-is, which caused confusing errors later on. Instead, report an invalid severity string right up front to make the problem clear. --- runtime/lua/vim/diagnostic.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua index b58055f07e..e8aba6b7a3 100644 --- a/runtime/lua/vim/diagnostic.lua +++ b/runtime/lua/vim/diagnostic.lua @@ -27,7 +27,10 @@ local global_diagnostic_options = { ---@private local function to_severity(severity) - return type(severity) == 'string' and M.severity[string.upper(severity)] or severity + if type(severity) == 'string' then + return assert(M.severity[string.upper(severity)], string.format("Invalid severity: %s", severity)) + end + return severity end ---@private