Skip to content

Commit

Permalink
more informative property parsing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rmfitzpatrick committed Jun 9, 2023
1 parent cfa4dfd commit 439028f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/confmapprovider/discovery/properties/conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestInvalidConf(t *testing.T) {
path: filepath.Join(".", "testdata", "invalid-mapping-unknown-component.yaml"),
},
{
expectedError: "invalid property (parsing error): splunk.discovery:1:18: unexpected token \"123\" (expected (\"receivers\" | \"extensions\") <dot> ComponentID <dot> ((\"config\" <dot>) | \"enabled\") (<string> | <dot> | <forwardslash>)*); invalid property (parsing error): splunk.discovery:1:18: unexpected token \"processors\" (expected (\"receivers\" | \"extensions\") <dot> ComponentID <dot> ((\"config\" <dot>) | \"enabled\") (<string> | <dot> | <forwardslash>)*); invalid property (parsing error): splunk.discovery:1:57: unexpected token \"<EOF>\" (expected <dot> ((\"config\" <dot>) | \"enabled\") (<string> | <dot> | <forwardslash>)*); invalid property (parsing error): splunk.discovery:1:87: unexpected token \"<EOF>\" (expected <dot> ((\"config\" <dot>) | \"enabled\") (<string> | <dot> | <forwardslash>)*)",
expectedError: `invalid property "splunk.discovery.123" (parsing error): splunk.discovery:1:18: unexpected token "123" (expected ("receivers" | "extensions") <dot> ComponentID <dot> (("config" <dot>) | "enabled") (<string> | <dot> | <forwardslash>)*); invalid property "splunk.discovery.processors.a_processor.config.some_field" (parsing error): splunk.discovery:1:18: unexpected token "processors" (expected ("receivers" | "extensions") <dot> ComponentID <dot> (("config" <dot>) | "enabled") (<string> | <dot> | <forwardslash>)*); invalid property "splunk.discovery.receivers.a_receiver.unknown.some_field" (parsing error): splunk.discovery:1:57: unexpected token "<EOF>" (expected <dot> (("config" <dot>) | "enabled") (<string> | <dot> | <forwardslash>)*); invalid property "splunk.discovery.receivers.another_receiver/with-name.another_unknown.some_other_field" (parsing error): splunk.discovery:1:87: unexpected token "<EOF>" (expected <dot> (("config" <dot>) | "enabled") (<string> | <dot> | <forwardslash>)*)`,
path: filepath.Join(".", "testdata", "invalid-set.yaml"),
},
} {
Expand Down
2 changes: 1 addition & 1 deletion internal/confmapprovider/discovery/properties/property.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type ComponentID struct {
func NewProperty(property, val string) (*Property, error) {
p, err := parser.ParseString("splunk.discovery", property)
if err != nil {
return nil, fmt.Errorf("invalid property (parsing error): %w", err)
return nil, fmt.Errorf("invalid property %q (parsing error): %w", property, err)
}
p.Val = val

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ func TestInvalidProperties(t *testing.T) {
for _, tt := range []struct {
property, expectedError string
}{
{property: "splunk.discovery.invalid", expectedError: "invalid property (parsing error): splunk.discovery:1:18: unexpected token \"invalid\" (expected (\"receivers\" | \"extensions\") <dot> ComponentID <dot> ((\"config\" <dot>) | \"enabled\") (<string> | <dot> | <forwardslash>)*)"},
{property: "splunk.discovery.extensions.config.one.two", expectedError: "invalid property (parsing error): splunk.discovery:1:43: unexpected token \"<EOF>\" (expected <dot> ((\"config\" <dot>) | \"enabled\") (<string> | <dot> | <forwardslash>)*)"},
{property: "splunk.discovery.receivers.type/name.config", expectedError: "invalid property (parsing error): splunk.discovery:1:44: unexpected token \"<EOF>\" (expected <dot>)"},
{property: "splunk.discovery.invalid", expectedError: "invalid property \"splunk.discovery.invalid\" (parsing error): splunk.discovery:1:18: unexpected token \"invalid\" (expected (\"receivers\" | \"extensions\") <dot> ComponentID <dot> ((\"config\" <dot>) | \"enabled\") (<string> | <dot> | <forwardslash>)*)"},
{property: "splunk.discovery.extensions.config.one.two", expectedError: "invalid property \"splunk.discovery.extensions.config.one.two\" (parsing error): splunk.discovery:1:43: unexpected token \"<EOF>\" (expected <dot> ((\"config\" <dot>) | \"enabled\") (<string> | <dot> | <forwardslash>)*)"},
{property: "splunk.discovery.receivers.type/name.config", expectedError: "invalid property \"splunk.discovery.receivers.type/name.config\" (parsing error): splunk.discovery:1:44: unexpected token \"<EOF>\" (expected <dot>)"},
} {
t.Run(tt.property, func(t *testing.T) {
p, err := NewProperty(tt.property, "val")
Expand Down

0 comments on commit 439028f

Please sign in to comment.