Repository navigation
Closed
Labels
Description
Observed behavior
transposeEvaluators doesn't behave correctly if the json passed to it doesn't have the right indentation.
Expected Behavior
transposeEvaluators should handle cases where the json passed to it doesn't have the right indentation.
Steps to reproduce
- Check out this PR's branch
- Put
fmt.Printlnstatements just after this line and after this line. - Use
json.Marshalinstead ofjson.MarshalIndenthere - From
flagdroot directory run (example_flags.yaml can be found here):
$ go run main.go start -f file:./config/samples/example_flags.yaml -e=yaml
{"level":"info","ts":1672807996.7619019,"caller":"service/connect_service.go:108","msg":"metrics listening at 8014","component":"service"}
evalValue before {"in":["@faas.com",{"var":["email"]}]}
evalValue after "in":["@faas.com",{"var":["email"]}
{"level":"fatal","ts":1672807996.762957,"caller":"cmd/start.go:116","msg":"set state: unmarshal new state: invalid character '}' after array element","component":"start","stacktrace":"github.com/open-feature/flagd/cmd.glob..func1\n\t/home/suraj/sandbox/flagd/cmd/start.go:116\ngithub.com/spf13/cobra.(*Command).execute\n\t/home/suraj/go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:860\ngithub.com/spf13/cobra.(*Command).ExecuteC\n\t/home/suraj/go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:974\ngithub.com/spf13/cobra.(*Command).Execute\n\t/home/suraj/go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:902\ngithub.com/open-feature/flagd/cmd.Execute\n\t/home/suraj/sandbox/flagd/cmd/root.go:38\nmain.main\n\t/home/suraj/sandbox/flagd/main.go:30\nruntime.main\n\t/usr/local/go/src/runtime/proc.go:250"}
exit status 1
If you check the above log,
evalValue before {"in":["@faas.com",{"var":["email"]}]}
evalValue after "in":["@faas.com",{"var":["email"]}
Because the trailing brackets are not on newline, flagd trims the last two trailing brackets which makes the json invalid. This problem doesn't happen if you use json.MarshalIndent like this
To contrast this with using a json config file,
$ go run main.go start -f file:./config/samples/example_flags.json -e=json
{"level":"info","ts":1672808353.423182,"caller":"service/connect_service.go:108","msg":"metrics listening at 8014","component":"service"}
evalValue before {
"in": ["@faas.com", {
"var": ["email"]
}]
}
evalValue after
"in": ["@faas.com", {
"var": ["email"]
}]
{"level":"info","ts":1672808353.4240851,"caller":"runtime/runtime.go:84","msg":"configuration change (write) for flagKey myBoolFlag (./config/samples/example_flags.json)","component":"runtime"}
...
There is no error. Looking at the log above,
evalValue before {
"in": ["@faas.com", {
"var": ["email"]
}]
}
evalValue after
"in": ["@faas.com", {
"var": ["email"]
}]
Notice how only the trailing bracket on newline is removed (with the opening bracket on the first line). Resulting json is valid.
Activity
vadasambar commentedon Jan 4, 2023
I am not sure if we want to fix this now or even fix this at all because we ran into this issue when we tried converting yaml to json (we might not have to do this anytime soon in the future) and we have a way to work around the issue using
json.MarshalIndentinstead ofjson.Marshal. I have created this issue for future reference in case anyone runs into a similar issue in the future.fix: replace character slice with regex replace (#250)
chore(main): release providers/configcat 0.1.1 (open-feature#244)