Add Error Checking for Non-specified Plugins (quality)
This commit is contained in:
parent
9b09754f0e
commit
93cbe0556c
|
@ -113,9 +113,13 @@ func (ap *appletPlugins) AddPlugin(peerid string, id plugins.PluginID, bus event
|
||||||
pluginsinf, _ := ap.plugins.Load(peerid)
|
pluginsinf, _ := ap.plugins.Load(peerid)
|
||||||
peerPlugins := pluginsinf.([]plugins.Plugin)
|
peerPlugins := pluginsinf.([]plugins.Plugin)
|
||||||
|
|
||||||
newp := plugins.Get(id, bus, acn, peerid)
|
newp,err := plugins.Get(id, bus, acn, peerid)
|
||||||
newp.Start()
|
if err == nil {
|
||||||
peerPlugins = append(peerPlugins, newp)
|
newp.Start()
|
||||||
log.Debugf("storing plugin for %v %v", peerid, peerPlugins)
|
peerPlugins = append(peerPlugins, newp)
|
||||||
ap.plugins.Store(peerid, peerPlugins)
|
log.Debugf("storing plugin for %v %v", peerid, peerPlugins)
|
||||||
|
ap.plugins.Store(peerid, peerPlugins)
|
||||||
|
} else {
|
||||||
|
log.Errorf("error adding plugin: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package plugins
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cwtch.im/cwtch/event"
|
"cwtch.im/cwtch/event"
|
||||||
|
"fmt"
|
||||||
"git.openprivacy.ca/openprivacy/connectivity"
|
"git.openprivacy.ca/openprivacy/connectivity"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,13 +22,13 @@ type Plugin interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get is a plugin factory for the requested plugin
|
// Get is a plugin factory for the requested plugin
|
||||||
func Get(id PluginID, bus event.Manager, acn connectivity.ACN, onion string) Plugin {
|
func Get(id PluginID, bus event.Manager, acn connectivity.ACN, onion string) (Plugin, error) {
|
||||||
switch id {
|
switch id {
|
||||||
case CONNECTIONRETRY:
|
case CONNECTIONRETRY:
|
||||||
return NewConnectionRetry(bus, onion)
|
return NewConnectionRetry(bus, onion), nil
|
||||||
case NETWORKCHECK:
|
case NETWORKCHECK:
|
||||||
return NewNetworkCheck(bus, acn)
|
return NewNetworkCheck(bus, acn), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil, fmt.Errorf("plugin not defined %v", id)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue