Skip to content

Commit

Permalink
fix: Module type without path
Browse files Browse the repository at this point in the history
  • Loading branch information
s2quake committed Feb 7, 2025
1 parent d3d89c3 commit 04ed5f2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
20 changes: 20 additions & 0 deletions sdk/node/Libplanet.Node/Actions/PluginLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,33 @@ internal static class PluginLoader
{
public static IActionLoader LoadActionLoader(string modulePath, string typeName)
{
if (Type.GetType(typeName) is { } type)
{
if (Activator.CreateInstance(type) is not IActionLoader obj)
{
throw new InvalidOperationException();
}

return obj;
}

var assembly = LoadAssembly(modulePath);
return Create<IActionLoader>(assembly, typeName);
}

public static IPolicyActionsRegistry LoadPolicyActionRegistry(
string relativePath, string typeName)
{
if (Type.GetType(typeName) is { } type)
{
if (Activator.CreateInstance(type) is not IPolicyActionsRegistry obj)
{
throw new InvalidOperationException();
}

return obj;
}

var assembly = LoadAssembly(relativePath);
return Create<IPolicyActionsRegistry>(assembly, typeName);
}
Expand Down
6 changes: 4 additions & 2 deletions sdk/node/Libplanet.Node/Services/ActionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ private static IActionLoader GetActionLoader(ActionOptions options)
{
if (options.ActionLoaderType != string.Empty)
{
var modulePath = options.ModulePath;
var modulePath = options.ModulePath != string.Empty
? Path.GetFullPath(options.ModulePath) : string.Empty;
var actionLoaderType = options.ActionLoaderType;
return PluginLoader.LoadActionLoader(modulePath, actionLoaderType);
}
Expand All @@ -30,7 +31,8 @@ private static IPolicyActionsRegistry GetPolicyActionsRegistry(ActionOptions opt
{
if (options.PolicyActionRegistryType != string.Empty)
{
var modulePath = options.ModulePath;
var modulePath = options.ModulePath != string.Empty
? Path.GetFullPath(options.ModulePath) : string.Empty;
var policyActionRegistryType = options.PolicyActionRegistryType;
return PluginLoader.LoadPolicyActionRegistry(modulePath, policyActionRegistryType);
}
Expand Down

0 comments on commit 04ed5f2

Please sign in to comment.