Skip to content

Commit

Permalink
add global config parse error info
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlanni committed Nov 28, 2022
1 parent 4eb91e6 commit a103314
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions plugins/wasm-go/pkg/matcher/rule_matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package matcher

import (
"errors"
"fmt"
"strings"

"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
Expand Down Expand Up @@ -102,10 +103,12 @@ func (m *RuleMatcher[PluginConfig]) ParseRuleConfig(config gjson.Result,
keyCount--
}
var pluginConfig PluginConfig
var globalConfigError error
if keyCount > 0 {
err := parsePluginConfig(config, &pluginConfig)
if err != nil {
proxywasm.LogInfof("parse global config failed, err:%v", err)
proxywasm.LogWarnf("parse global config failed, err:%v", err)
globalConfigError = err
} else {
m.globalConfig = pluginConfig
m.hasGlobalConfig = true
Expand All @@ -115,7 +118,7 @@ func (m *RuleMatcher[PluginConfig]) ParseRuleConfig(config gjson.Result,
if m.hasGlobalConfig {
return nil
}
return errors.New("parse config failed, no valid rules")
return fmt.Errorf("parse config failed, no valid rules; global config parse error:%v", globalConfigError)
}
for _, ruleJson := range rules {
var rule RuleConfig[PluginConfig]
Expand Down
2 changes: 1 addition & 1 deletion plugins/wasm-go/pkg/matcher/rule_matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func TestParseRuleConfig(t *testing.T) {
{
name: "no rule",
config: `{"_rules_":[]}`,
errMsg: "parse config failed, no valid rules",
errMsg: "parse config failed, no valid rules; global config parse error:<nil>",
},
{
name: "invalid rule",
Expand Down

0 comments on commit a103314

Please sign in to comment.