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

Failed to update environment: invalid character '<' looking for beginning of value #135

Closed
nishant-shah-social opened this issue Jul 25, 2024 · 9 comments · Fixed by #139
Assignees

Comments

@nishant-shah-social
Copy link

Intermittently getting following errors after upgrading to the golang client sdk version 3.5.0:-
Failed to update environment: invalid character '<' looking for beginning of value
"Failed to update environment: invalid character 'E' looking for beginning of value"
Any help will be highly appreciated

Thanks!

@matthewelwell
Copy link
Contributor

Hi @nishant-shah-social, can you provide a bit more information here please? Where are you seeing this error please?

If you can provide information about your setup, that would be very helpful.

For example, the following details will be necessary for us to investigate this:

  1. How are you running Flagsmith? SaaS or self-hosted?
  2. How are you initialising your SDK? Please provide code examples where possible.

Any other information you can provide that might help us will be very helpful as well. Thanks!

@nishant-shah-social
Copy link
Author

nishant-shah-social commented Jul 25, 2024

Hi @nishant-shah-social, can you provide a bit more information here please? Where are you seeing this error please?

If you can provide information about your setup, that would be very helpful.

For example, the following details will be necessary for us to investigate this:

  1. How are you running Flagsmith? SaaS or self-hosted?
  2. How are you initialising your SDK? Please provide code examples where possible.

Any other information you can provide that might help us will be very helpful as well. Thanks!

Sure @matthewelwell !
We are using flagsmith self-hosted. The server is at version 2.129.0
We are using local evaluation mode

the code snippet

flagsmithConf := flagsmith.Configuration{
		Environment:                cfg.FlagsmithClient.Environment,
		ApplicationName:            cfg.FlagsmithClient.ApplicationName,
		ServerSideAPIKey:           cfg.FlagsmithClient.ServerSideApiKey,
		ClientSideAPIKey:           cfg.FlagsmithClient.ClientSideApikey,
		BaseURL:                    cfg.FlagsmithClient.BaseURL,
		RequestTimeout:             cfg.FlagsmithClient.RequestTimeout,
		Retries:                    cfg.FlagsmithClient.Retries,
		RetryDelayInterval:         cfg.FlagsmithClient.RetryDelayInterval,
		EnvironmentRefreshInterval: cfg.FlagsmithClient.EnvironmentRefreshInterval,
		EvaluationMode:             flagsmith.EvaluationMode(cfg.FlagsmithClient.EvaluationMode),
		FlagsmithCtx:               flagsmithCtx,
		PrometheusRegisterer:       reg,
		Logger:                     l,
		UserAgent:                  fmt.Sprintf("%s,%s", cfg.FlagsmithClient.ApplicationName, cfg.FlagsmithClient.Environment),
	}

	flagClient, err := flagsmith.NewFlagsmithClient(flagsmithConf)

where NewflagsmithClient() has the logic to set all the options and then initialize flagsmith with something like:-

client := flagsmith.NewClient(apiKey, flagsmithOpts...)

While evaluation, we use following call:-

identityFlags, err := fg.Client.GetIdentityFlags(fg.ctx, idStr, fgTraits)

Hope this helps! Let me know if any further info is required

Thanks,
Nishant Shah

@matthewelwell
Copy link
Contributor

Thanks for the details @nishant-shah-social, we'll take a look into this and update here with any findings.

@nishant-shah-social
Copy link
Author

@gagantrivedi incase you got time to look into it?

@rolodato
Copy link
Member

rolodato commented Aug 8, 2024

@nishant-shah-social The error sounds like your self-hosted Flagsmith is returning HTML instead of JSON. Could you double check that your API URL is something like https://flagsmith.example.com/api/v1/? The trailing slash is needed.

@matthewelwell
Copy link
Contributor

@nishant-shah-social did you have a chance to confirm regarding the outstanding question here?

@nishant-shah-social
Copy link
Author

@rolodato @matthewelwell Sorry for the delayed response. Our API URL does have this trailing slash. I see this error happening intermittently and not always. Further investigations revealed that his error occurs when due to some reason SDK is unable to connect to flagsmith when trying to call update environment. Still I would expect some logical error instead of this

@rolodato
Copy link
Member

I believe we're not handling this case correctly, where the API responds with a non-JSON 4xx-5xx response:

if res.StatusCode >= 400 {
if r.err != nil {
if err := json.Unmarshal(bodyBytes, r.err); err != nil {
.

There's probably no need to unmarshal JSON at all here and we can just return the status code as an error, which is what we're trying to do here anyway:

return &response{
body: bodyBytes,
statusCode: res.StatusCode,
status: res.Status,
}, errors.New(res.Status)
. We'd appreciate a PR for this if you have the time :)

@gagantrivedi gagantrivedi linked a pull request Sep 10, 2024 that will close this issue
@rolodato
Copy link
Member

@nishant-shah-social Are you able to reproduce this same error with the latest 3.6.0? You should be able to see more details now on what's going wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants