Quellcode durchsuchen

fix(portable): if no plugin, list portable plugins should return []

1. Currently, nil is return. Change to []
2. Let the function runtime print byte array as string in error

Signed-off-by: Jiyong Huang <huangjy@emqx.io>
Jiyong Huang vor 3 Jahren
Ursprung
Commit
65b8f17285

+ 2 - 1
internal/plugin/portable/registry.go

@@ -70,7 +70,8 @@ func (r *registry) GetSymbol(pt plugin.PluginType, symbolName string) (string, b
 func (r *registry) List() []*PluginInfo {
 func (r *registry) List() []*PluginInfo {
 	r.RLock()
 	r.RLock()
 	defer r.RUnlock()
 	defer r.RUnlock()
-	var result []*PluginInfo
+	// return empty slice instead of nil to help json marshal
+	result := make([]*PluginInfo, 0, len(r.plugins))
 	for _, v := range r.plugins {
 	for _, v := range r.plugins {
 		result = append(result, v)
 		result = append(result, v)
 	}
 	}

+ 1 - 1
internal/plugin/portable/runtime/function.go

@@ -135,7 +135,7 @@ func (f *PortableFunc) IsAggregate() bool {
 	if fr.State {
 	if fr.State {
 		r, ok := fr.Result.(bool)
 		r, ok := fr.Result.(bool)
 		if !ok {
 		if !ok {
-			conf.Log.Errorf("IsAggregate result is not bool, got %v", res)
+			conf.Log.Errorf("IsAggregate result is not bool, got %s", string(res))
 			return false
 			return false
 		} else {
 		} else {
 			return r
 			return r