Skip to content

Commit

Permalink
fix(package): emit registry event on abnormal failures (#1061)
Browse files Browse the repository at this point in the history
Also display a more helpful error message in the UI, as well as terminating the handle if it's not yet terminated.
  • Loading branch information
williamboman committed Mar 5, 2023
1 parent 08db751 commit 35e33e4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lua/mason-core/package/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,19 @@ function Package:install(opts)
---@param result Result
function(success, result)
if not success then
-- Installer failed abnormally (i.e. unexpected exception in the installer code itself).
log.error("Unexpected error", result)
handle.stdio.sink.stderr(tostring(result))
handle.stdio.sink.stderr "\nInstallation failed abnormally. Please report this error."
self:emit("install:failed", handle)
registry:emit("package:install:failed", self, handle)

-- We terminate _after_ emitting failure events because [termination -> failed] have different
-- meaning than [failed -> terminate] ([termination -> failed] is interpreted as a triggered
-- termination).
if not handle:is_closed() and not handle.is_terminated then
handle:terminate()
end
return
end
result
Expand Down

0 comments on commit 35e33e4

Please sign in to comment.