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

Fix error formatting in JQ mapper #358

Merged
merged 1 commit into from
Jul 22, 2024
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
10 changes: 5 additions & 5 deletions pkg/transform/jq.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (jqm *jqMapper) RunFunction() TransformationFunction {
// no looping since we only keep first value
v, ok := iter.Next()
if !ok {
message.SetError(fmt.Errorf("jq query got no output"))
message.SetError(errors.New("jq query got no output"))
return nil, nil, message, nil
}

Expand All @@ -66,7 +66,7 @@ func (jqm *jqMapper) RunFunction() TransformationFunction {
// here v is any, so we Marshal. alternative: gojq.Marshal
data, err := json.Marshal(v)
if err != nil {
message.SetError(fmt.Errorf("error encoding jq query output data"))
message.SetError(errors.New("error encoding jq query output data"))
return nil, nil, message, nil
}

Expand Down Expand Up @@ -95,7 +95,7 @@ func jqMapperAdapterGenerator(f func(c *JQMapperConfig) (TransformationFunction,
return func(i interface{}) (interface{}, error) {
cfg, ok := i.(*JQMapperConfig)
if !ok {
return nil, fmt.Errorf("invalid input, expected JQMapperConfig")
return nil, errors.New("invalid input, expected JQMapperConfig")
}

return f(cfg)
Expand All @@ -106,7 +106,7 @@ func jqMapperAdapterGenerator(f func(c *JQMapperConfig) (TransformationFunction,
func jqMapperConfigFunction(c *JQMapperConfig) (TransformationFunction, error) {
query, err := gojq.Parse(c.JQCommand)
if err != nil {
return nil, fmt.Errorf("error parsing jq command: %q", err.Error())
return nil, fmt.Errorf("error parsing jq command: %s", err)
}

withEpochFunction := gojq.WithFunction("epoch", 0, 1, func(a1 any, a2 []any) any {
Expand All @@ -125,7 +125,7 @@ func jqMapperConfigFunction(c *JQMapperConfig) (TransformationFunction, error) {

code, err := gojq.Compile(query, withEpochFunction)
if err != nil {
return nil, fmt.Errorf("error compiling jq query: %q", err.Error())
return nil, fmt.Errorf("error compiling jq query: %s", err)
}

jq := &jqMapper{
Expand Down
2 changes: 1 addition & 1 deletion pkg/transform/jq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ func TestJQMapperConfigFunction(t *testing.T) {
{
Scenario: "parsing_error",
JQCommand: `^`,
Error: errors.New("error parsing jq command"),
Error: errors.New(`error parsing jq command: unexpected token "^"`),
},
}

Expand Down
Loading