Skip to content
This repository has been archived by the owner on Dec 28, 2021. It is now read-only.

Correctly interpret string arguments as booleans in electron arguments. #1536

Merged
merged 4 commits into from
May 4, 2021

Conversation

MichaelMauderer
Copy link
Contributor

@MichaelMauderer MichaelMauderer commented Apr 29, 2021

Pull Request Description

Previously arguments were passed to the main function as strings when using the electron app, or as booleans when using the development environment. Since false is a truthy value that was not further checked, this lead to wrong settings.
This PR adds a conversion of true and false to their boolean values, and adds an assertion that ensures that arguments are actually booleans.

Checklist

Please include the following checklist in your PR:

  • The CHANGELOG.md was updated with the changes introduced in this PR.
  • The documentation has been updated if necessary.
  • All code conforms to the Rust style guide.
  • All code has automatic tests where possible.
  • All code has been profiled where possible.
  • All code has been manually tested in the IDE.
  • All code has been manually tested in the "debug/interface" scene.
  • All code has been manually tested by the PR owner against our test scenarios.
  • All code has been manually tested by at least one reviewer against our test scenarios.

@MichaelMauderer MichaelMauderer self-assigned this Apr 29, 2021
@MichaelMauderer MichaelMauderer added Category: GUI The Graphical User Interface Difficulty: Hard Significant prior knowledge requried Priority: Highest Should be completed ASAP Type: Bug A bug in Enso IDE labels Apr 29, 2021
@MichaelMauderer MichaelMauderer marked this pull request as ready for review April 29, 2021 13:28
@@ -438,6 +439,36 @@ function ok(value) {
return value !== null && value !== undefined
}

/// Check whether the value is a string with value `"true"`/`"false"`, if so, return the
// appropriate boolean instead. Otherwise, return the original value.
function tryAsBoolean(value) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the name of the function could be more descriptive, like parseBooleanOrLeaveAsIs I know its longer, but "try" in name tells me that we are returning something like Option, but here we are returning the original value. It could also be tryAsBooleanOrLeaveAsIs, but parse is better as it tells that we are working with string input.

Comment on lines 454 to 460
/// Turn all values that have a boolean in string representation (`"true"`/`"false"`) into actual
/// booleans (`true/`false``).
function ensureBooleans(config) {
for (const key in config) {
config[key] = tryAsBoolean(config[key])
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd call it parseAllBooleans instead - I think this name is more descriptive.

@mwu-tow
Copy link
Contributor

mwu-tow commented Apr 29, 2021

I think this should be connected to https://github.com/enso-org/ide/issues/1512
Also converting other well-known types (like numbers) might have sense here.

@MichaelMauderer
Copy link
Contributor Author

I think this should be connected to #1512
Also converting other well-known types (like numbers) might have sense here.

I think, ideally we would convert the whole file (and all JS files bit by bit) to TypeScript and implement this properly using a Config class that gets instantiated and validates its fields.

@MichaelMauderer
Copy link
Contributor Author

Closed in favour of #1539

@MichaelMauderer MichaelMauderer merged commit d659d6e into develop May 4, 2021
@MichaelMauderer MichaelMauderer deleted the wip/mm/fix-js-argument-parsing branch May 4, 2021 09:13
mwu-tow pushed a commit to enso-org/enso that referenced this pull request Oct 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Category: GUI The Graphical User Interface Difficulty: Hard Significant prior knowledge requried Priority: Highest Should be completed ASAP Type: Bug A bug in Enso IDE
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants