Skip to content

Commit 89b75a1

Browse files
committed
feat: Refactor plugin loading to remove registry checks for subnet_calculator and improve error messaging
1 parent 0dd867b commit 89b75a1

1 file changed

Lines changed: 9 additions & 27 deletions

File tree

app/plugins/plugin_loader_helper.go

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@ func LoadPluginFunc(pluginDir, pluginID string) (func(map[string]interface{}) (i
4040
return nil, fmt.Errorf("no Go files found for plugin %s", pluginID)
4141
}
4242

43-
// Use an adapter-like approach to call the plugin's Execute function
44-
// This is a special case for our subnet_calculator plugin that uses executeAdapter
45-
if pluginID == "subnet_calculator" {
46-
registry := GetRegistry()
47-
execFunc, err := registry.GetPluginFunc(pluginID)
48-
if err == nil {
49-
return execFunc, nil
50-
}
51-
}
52-
5343
// Dynamic import based on plugin directory
5444
// The plugin must have a Plugin() function that returns a map with an "execute" key
5545
return func(params map[string]interface{}) (interface{}, error) {
@@ -94,17 +84,13 @@ func LoadPluginFunc(pluginDir, pluginID string) (func(map[string]interface{}) (i
9484
case "wifi_scanner":
9585
return executeWifiScanner(params)
9686
default:
97-
// For other plugins, first try the registry (pre-registered plugins)
98-
registry := GetRegistry()
99-
if execFunc, err := registry.GetPluginFunc(pluginID); err == nil {
100-
return execFunc(params)
101-
}
102-
103-
// Then try to use pre-compiled dynamically loaded plugin (.so file)
87+
// For unknown plugins, try to use pre-compiled dynamically loaded plugin (.so file)
88+
// NOTE: Do NOT check the registry here - this function IS what gets registered
89+
// in the registry, so checking it would cause infinite recursion
10490
pluginPath := filepath.Join(pluginDir, pluginID+".so")
10591
if _, err := os.Stat(pluginPath); os.IsNotExist(err) {
106-
// No .so file and not in registry - plugin not available
107-
return nil, fmt.Errorf("plugin %s not found: no pre-compiled .so file and not registered", pluginID)
92+
// No .so file - plugin not available for dynamic execution
93+
return nil, fmt.Errorf("plugin %s not found: no pre-compiled .so file available", pluginID)
10894
}
10995

11096
// Try to load the pre-compiled plugin
@@ -151,19 +137,15 @@ func executeCommand(command string) (string, error) {
151137
// but for now, we'll implement them with direct imports or simple placeholder functionality
152138

153139
func executeSubnetCalculator(params map[string]interface{}) (interface{}, error) {
154-
// First try the registry (pre-registered plugins - no Go compiler needed)
155-
registry := GetRegistry()
156-
if execFunc, err := registry.GetPluginFunc("subnet_calculator"); err == nil {
157-
return execFunc(params)
158-
}
159-
160-
// Then try to use a pre-compiled dynamic plugin (.so file)
140+
// Try to use a pre-compiled dynamic plugin (.so file)
141+
// NOTE: Do NOT check the registry here - this function can be called from
142+
// LoadPluginFunc which itself gets registered, causing infinite recursion
161143
pluginDir := filepath.Join("app", "plugins", "plugins", "subnet_calculator")
162144
pluginPath := filepath.Join(pluginDir, "subnet_calculator.so")
163145

164146
// Check if pre-compiled plugin exists
165147
if _, err := os.Stat(pluginPath); os.IsNotExist(err) {
166-
return nil, fmt.Errorf("subnet_calculator plugin not available: not registered and no pre-compiled .so file")
148+
return nil, fmt.Errorf("subnet_calculator plugin not available: no pre-compiled .so file")
167149
}
168150

169151
// Try to load the pre-compiled plugin

0 commit comments

Comments
 (0)