usebruno / bruno

Opensource IDE For Exploring and Testing Api's (lightweight alternative to postman/insomnia)
https://www.usebruno.com/
MIT License
27.4k stars 1.26k forks source link

White screen on environment variables page after setting numeric value with bru.setEnvVar #914

Closed langfeld closed 10 months ago

langfeld commented 1 year ago

Description

There seems to be an issue with the Bruno REST client where storing a numeric value using the bru.setEnvVar function causes the Environment Variables overview page to fail to load. The page stays blank until Bruno is restarted. However, when storing a numeric value as a string, this issue does not occur.

Steps to Reproduce

  1. Go to the Script section under Post Response.
  2. Execute the following line of code to set a numeric value: bru.setEnvVar("locationId", 123);
  3. Attempt to open the Environment Variables overview page - the issue occurs, the page stays white.
  4. Restart Bruno REST client, repeat step 1.
  5. Execute the following line of code to set a numeric value as a string: bru.setEnvVar("locationId", String(123));
  6. Attempt to open the Environment Variables overview page again - this time, the issue does not occur, and the page loads correctly.

Expected Behavior

The Environment Variables overview page should open without issues, showing the list of variables, regardless of whether the value set is numeric or a string.

Actual Behavior

When a numeric value is set with bru.setEnvVar("locationId", 123);, the Environment Variables overview page does not load and remains blank. Only after restarting the Bruno REST client does the page become accessible again. Conversely, setting the value as a string with bru.setEnvVar("locationId", String(123)); does not lead to this issue.

Additional Information

The issue appears to be specific to setting numeric values directly. I have not encountered this problem when setting strings or booleans.

Any assistance in resolving this would be greatly appreciated.

whoistobias commented 1 year ago

I'm able to reproduce this error with 100% consistency on the Windows client.

The console shows an error that says "TypeError: e.split is not a function"

martinsefcik commented 1 year ago

It can be simple fixed on https://github.com/usebruno/bruno/blob/ba761098be216e802399e8888974377fbe6bbe4b/packages/bruno-app/src/components/SingleLineEditor/index.js#L125 by converting this.props.value to string if it is not a string. But I think in generally it is a bit more complex issue, because If I am not mistaken Bruno allows to store env variables only as strings in bru file. So in the end this numeric value will be saved as string in bru file and not as number. Probably somebody can expect that if number was stored via setEnvVar, then number should be retrieved if I call getEnvVar for the same variable anytime (e.g. after application restart). And it also doesn't have to be number only, but probably more complex object. What should be done then? Should we convert object to string json representation?

So the main question here is how it should behave and whether there are any plans in future to support storing any kind of values and not only strings in env variables (in bru file).

cc: @helloanoop

martinsefcik commented 1 year ago

Related to #847 and #950

helloanoop commented 10 months ago

Just merged the fix from @nguyenbavinh-decathlon !

So in the end this numeric value will be saved as string in bru file and not as number.

@martinsefcik This will still get stored as a number in the bru file. Currently bru file doesn't differentiate a string and number, everything is stored in plain text. The type is inferred at the time of loading the file.

how it should behave and whether there are any plans in future to support storing any kind of values and not only strings in env variables (in bru file).

So, as of today, we can only store strings and numbers. Due to the nature of the single line editor, it will hard to support storing arrays or objects.

In the future there is plan to support Nested Environments (#292) where a user can choose to get and set the environment by directly updating the json (in this case the environment will be a json file)