Good Code
The good version catches plugin failures and turns them into a structured error table. The host can log the plugin name, disable it, or show a controlled message.
Lesson 06
Wrap untrusted or plugin code with pcall and convert failures into typed results for the host app.
local function run_plugin(plugin, review)
-- pcall keeps plugin errors from unwinding the host process.
local ok, result = pcall(plugin.review, review)
if not ok then
return nil, { code = "plugin_error", message = result }
end
return result
endlocal function run_plugin(plugin, review)
-- A plugin error escapes without host context.
return plugin.review(review)
endThe good version catches plugin failures and turns them into a structured error table. The host can log the plugin name, disable it, or show a controlled message.
The bad version calls plugin code directly. A plugin error escapes through the host path without enough context for recovery.