summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--locale/en-us/script.lua6
-rw-r--r--locale/zh-cn/script.lua6
-rw-r--r--script/client.lua10
-rw-r--r--script/plugin.lua20
4 files changed, 41 insertions, 1 deletions
diff --git a/locale/en-us/script.lua b/locale/en-us/script.lua
index 41bcc715..2125ee0c 100644
--- a/locale/en-us/script.lua
+++ b/locale/en-us/script.lua
@@ -245,3 +245,9 @@ WINDOW_ASK_APPLY_LIBRARY = 'Do you need to configure your work environme
CONFIG_LOAD_FAILED = 'Unable to read the settings file: {}'
CONFIG_LOAD_ERROR = 'Setting file loading error: {}'
CONFIG_TYPE_ERROR = 'The setting file must be in lua or json format: {}'
+
+PLUGIN_RUNTIME_ERROR = [[
+An error occurred in the plugin, please report it to the plugin author.
+Please check the details in the output or log.
+Plugin path: {}
+]]
diff --git a/locale/zh-cn/script.lua b/locale/zh-cn/script.lua
index c6971502..a1619b98 100644
--- a/locale/zh-cn/script.lua
+++ b/locale/zh-cn/script.lua
@@ -244,3 +244,9 @@ WINDOW_ASK_APPLY_LIBRARY = '是否需要将你的工作环境配置为 `
CONFIG_LOAD_FAILED = '无法读取设置文件:{}'
CONFIG_LOAD_ERROR = '设置文件加载错误:{}'
CONFIG_TYPE_ERROR = '设置文件必须是lua或json格式:{}'
+
+PLUGIN_RUNTIME_ERROR = [[
+插件发生错误,请汇报给插件作者。
+请在输出或日志中查看详细信息。
+插件路径:{}
+]]
diff --git a/script/client.lua b/script/client.lua
index 12020fe5..92bb1327 100644
--- a/script/client.lua
+++ b/script/client.lua
@@ -168,6 +168,15 @@ function m.editText(uri, edits)
})
end
+local function hookPrint()
+ if TEST then
+ return
+ end
+ print = function (...)
+ m.logMessage('Log', ...)
+ end
+end
+
function m.init(t)
log.debug('Client init', util.dump(t))
m.info = t
@@ -175,6 +184,7 @@ function m.init(t)
m.client(t.clientInfo.name)
nonil.disable()
lang(LOCALE or t.locale)
+ hookPrint()
end
return m
diff --git a/script/plugin.lua b/script/plugin.lua
index 15c7c311..3dbb1b66 100644
--- a/script/plugin.lua
+++ b/script/plugin.lua
@@ -1,9 +1,19 @@
local config = require 'config'
local util = require 'utility'
+local client = require 'client'
+local lang = require 'language'
---@class plugin
local m = {}
+function m.showError(err)
+ if m._hasShowedError then
+ return
+ end
+ m._hasShowedError = true
+ client.showMessage('Error', lang.script('PLUGIN_RUNTIME_ERROR', m.pluginPath, err))
+end
+
function m.dispatch(event, ...)
if not m.interface then
return false
@@ -17,6 +27,8 @@ function m.dispatch(event, ...)
tracy.ZoneEnd()
if suc then
return true, res1, res2
+ else
+ m.showError(res1)
end
return false, res1
end
@@ -45,13 +57,19 @@ function m.init()
if not pluginLua then
return
end
+ m.pluginPath = pluginPath
local env = setmetatable(m.interface, { __index = _ENV })
local f, err = load(pluginLua, '@'..pluginPath, "t", env)
if not f then
log.error(err)
+ m.showError(err)
+ return
+ end
+ local suc, err = xpcall(f, log.error, f)
+ if not suc then
+ m.showError(err)
return
end
- xpcall(f, log.error, f)
resetFiles()
end