Skip to content

Commit 0e5bd14

Browse files
committed
fix(core): rewrite modular provider logic
pcall will now actually catch any errors that occur when we require the provider. Instead of several if-blocks, just assert that type(provider) == "function". This catches all of our previous edge-cases, like when provider == nil.
1 parent 7733420 commit 0e5bd14

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

unicorn/core.lua

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,18 @@ end
8585
-- If found, it uses that provider to install files to the system.
8686
-- Otherwise, it errors.
8787
local function action_modular_providers(package_table)
88-
local match, provider = pcall(require("unicorn.provider." .. package_table.pkgType))
89-
90-
if type(provider) == "function" then
88+
local match, provider = pcall(require, "unicorn.provider." .. package_table.pkgType)
89+
if match then
90+
assert(type(provider) == "function", "The package provider "
91+
.. package_table.pkgType
92+
.. "is malformed (type should be function). Something is wrong with the provider's backend code. Unless you are writing your own provider, please report this error.")
9193
provider(package_table)
92-
end
93-
94-
-- catch unknown providers
95-
if not match then
96-
if not package_table.pkgType == nil then
97-
error(
98-
"Package provider "
99-
.. package_table.pkgType
100-
.. " is unknown. You are either missing the appropriate package provider or something is wrong with the package."
101-
)
102-
end
94+
else
95+
error(
96+
"Package provider "
97+
.. package_table.pkgType
98+
.. " is unknown. You are either missing the appropriate package provider or something is wrong with the package."
99+
)
103100
end
104101
end
105102

0 commit comments

Comments
 (0)