From 35e33e4b6df6130a79fa91ee2dd7e1318be8dc88 Mon Sep 17 00:00:00 2001 From: William Boman Date: Sun, 5 Mar 2023 03:21:54 +0100 Subject: fix(package): emit registry event on abnormal failures (#1061) Also display a more helpful error message in the UI, as well as terminating the handle if it's not yet terminated. --- lua/mason-core/package/init.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lua/mason-core/package/init.lua') diff --git a/lua/mason-core/package/init.lua b/lua/mason-core/package/init.lua index 5060ff5c..88e89c41 100644 --- a/lua/mason-core/package/init.lua +++ b/lua/mason-core/package/init.lua @@ -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 -- cgit v1.2.3-70-g09d2