Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add global config parse error #65

Merged
merged 1 commit into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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