Skip to content

Commit

Permalink
fix(diagnostic): error on invalid severity value (#15965)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gpanders committed Oct 8, 2021
1 parent 3f09732 commit d5dd0aa
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion runtime/lua/vim/diagnostic.lua
Expand Up @@ -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
Expand Down

0 comments on commit d5dd0aa

Please sign in to comment.