Setting the env variable through script cause error on setting manually error
I have checked the following:
- [X] I use the newest version of bruno.
- [X] I've searched existing issues and found nothing related to my issue.
Describe the bug
Reproduce process
- Running a request and there is pre script to setup some env variables.
- Edit the env variable (same or different) manually
- Click save
- Show error "An error occurred while saving the changes"
Resolution for now
- Need to restart the bruno everytime to edit the env variable after every request.
.bru file to reproduce the bug
No response
+1
I experienced this, too and was just about to create an issue.
In my case it is a post script and the error occurs on every change to the environment.
Hi, @developer-sunnywu , I was able to reproduce this issue and we're working on this. Thanks for reporting!
Hi @developer-sunnywu , @JoergJans, this issue no longer happens to me in 1.35. Can you check it out? Thanks!
@sreelakshmi-bruno I am using v.1.36.1, the problem still persist, can you help to check? Thanks
I've had the same issue on v1.38.1. After opening Console (Ctrl+Shift+I) I discovered that, in my case, the issue was Global environment variable stored as integer instead of string. I stored some values during postprocessing of the response and saved some integer values. After that, no variable can be modified, nor programmatically nor via Editor. I manually edited the Environment definition file, converting integers into strings, and after that everything was working fine again, Workaround that I use at the moment is to store every variable as string. I hope this helps.
I've had the same issue on v1.38.1. After opening Console (Ctrl+Shift+I) I discovered that, in my case, the issue was Global environment variable stored as integer instead of string. I stored some values during postprocessing of the response and saved some integer values. After that, no variable can be modified, nor programmatically nor via Editor. I manually edited the Environment definition file, converting integers into strings, and after that everything was working fine again, Workaround that I use at the moment is to store every variable as string. I hope this helps.
That fixed my case, thanks!
Apologies for the delay it's taking to fix this issue. We have a draft PR in place which attempts to solve this issue. Since it's a key change, it'll take more time to approve the approach and merge it. Until then, manually stringifying the variables before storing it seems to be the workaround. Thanks!
I am having this issue in version 2.0.1 when trying to save a change to a Global Environment variable.
Same issue on 2.3.0, when I try to add a global env variable, If I restart the app it works but it seems like when i send some requests and then try to add another var I get the same error "An error occurred while saving the changes"
@MikeJacquot This issue might be occurring because you're assigning an object to a Global Variable in your requests, rather than a string or number.
While you can set and retrieve objects using the bru.setGlobalEnvVar() API, the Bruno UI currently only supports primitive values (strings and numbers) for global variables. As a result, saving or editing variables through the UI can cause it to break.
We’re aware of this limitation and are working on a solution. In the meantime, a temporary workaround is to use bru.setVar() and bru.getVar() instead. These APIs store values in memory rather than the global environment. However, keep in mind that these values are ephemeral and will be lost when you restart the app.
I have an issue that is similar to the scenario above.
- I have a request with a post-script that sets the environment variable
bru.setEnvVar("token",res("access_token")); - When I send the request, the environment variable gets set. (Let's call this request 1)
- When I use the
tokenvariable in a subsequent request ( let's call it Request 2), it works fine. - Now, if I edit the environment variable
tokenmanually with a new value, it gets updated in the environment variable. I can see it updated. - When I run Request 2 this time (assuming it will pick up the manually updated value), it still uses the value that was set by request 1.
- Only after I restart the application, Request 2 picks up the manually updated value.
@amrutprabhu If you’ve set any object/integer via script, it ends up corrupting the environment. After that, any manual updates won’t get saved to the file.
Bruno doesn’t throw an error when you try to update manually, but you’ll notice the “Changes saved successfully” pop-up doesn’t show up.
As a workaround for now, you can stringify any objects before setting them via script. A similar issue also exists in the global environment: #4680 (comment)
@amrutprabhu If you’ve set any object/integer via script, it ends up corrupting the environment. After that, any manual updates won’t get saved to the file.
Bruno doesn’t throw an error when you try to update manually, but you’ll notice the “Changes saved successfully” pop-up doesn’t show up.
As a workaround for now, you can stringify any objects before setting them via script. A similar issue also exists in the global environment: #4680 (comment)
I did try to stringify the object before setting it, and I still get the same behaviour.
bru.setEnvVar("token",JSON.stringify(res("access_token")));
Also, when I try saving the value manually, "Changes saved successfully" does pop up, and when I try to use the variable, it still uses what was stored by the script earlier.
Hi @amrutprabhu would you be able to share a sample collection with me to reproduce this?
Hi, this issue is no longer reproducible in the latest version (v2.13.2). We’ve fixed the bug where setting an env to a non-string value would corrupt it, and we’ve also added multiline support for env variables.
I’m closing this issue as it has been resolved. Please feel free to reopen it if you run into any related problems again.