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

fix: getToggle by name may not find the toggle #455

Merged
merged 1 commit into from
May 22, 2023

Conversation

gastonfournier
Copy link
Contributor

About the changes

Node SDK interface should notify that getting a toggle by name can return undefined if the toggle does not exist:
https://github.com/Unleash/unleash/blob/d298b04cb2864b4853ca456e402714c98adaf932/src/lib/proxy/proxy-repository.ts#L75-L77

@gastonfournier gastonfournier self-assigned this May 16, 2023
@coveralls
Copy link

coveralls commented May 16, 2023

Coverage Status

Coverage: 91.617%. Remained the same when pulling cfdfd6c on find-may-not-find into 55274e4 on main.

Copy link
Contributor

@thomasheartman thomasheartman left a comment

Choose a reason for hiding this comment

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

Looks like a sensible change to me: I love that we're explicit about returning undefined if the feature doesn't exist 😄 But I've got a question on relaxing function parameters: I'm not sure we should allow isFeatureEnabled to be called with an undefined feature. 🤔 But that said, I'm guessing we already do that today, so this PR only updates the code to reflect reality and does not do anything to address any issues?

Comment on lines +73 to +77
isFeatureEnabled(
feature: FeatureInterface | undefined,
context: Context,
fallback: Function,
): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we changing the accepted parameter value? Surely, there's no point in ever calling this with a feature that's undefined? Wouldn't it be better to only allow you to call it with a defined feature?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes! Very good point, this is just the result of type refactoring, but I can look into this as it definitely makes sense!

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 more interesting question is: why is this method public? It's called by isEnabled which takes a string, resolves a toggle and calls this with the results and therefore and be called with an undefined. But what else is actually using this?

Copy link
Contributor Author

@gastonfournier gastonfournier May 22, 2023

Choose a reason for hiding this comment

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

Ok, I analyzed the option of always receiving something defined, but that'd be a breaking change. Right now this method accepts undefined but the type system does not reflect that. The proof is this line in the method body:

isFeatureEnabled(feature: FeatureInterface, context: Context, fallback: Function): boolean {
if (!feature) {
return fallback();
}

So, we're not changing the parameter value, we're just making it reflect the reality

Copy link
Member

@sighphyre sighphyre left a comment

Choose a reason for hiding this comment

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

Spec tests pass, change looks reasonable LGTM

Copy link
Member

@ivarconr ivarconr left a comment

Choose a reason for hiding this comment

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

Nice. I consider this a bug-fix.

@gastonfournier gastonfournier merged commit 41775cc into main May 22, 2023
@gastonfournier gastonfournier deleted the find-may-not-find branch May 22, 2023 09:31
renovate bot referenced this pull request in Unleash/unleash Jun 9, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [unleash-client](https://togithub.com/Unleash/unleash-client-node) |
[`3.20.0` ->
`3.21.0`](https://renovatebot.com/diffs/npm/unleash-client/3.20.0/3.21.0)
|
[![age](https://badges.renovateapi.com/packages/npm/unleash-client/3.21.0/age-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://badges.renovateapi.com/packages/npm/unleash-client/3.21.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://badges.renovateapi.com/packages/npm/unleash-client/3.21.0/compatibility-slim/3.20.0)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://badges.renovateapi.com/packages/npm/unleash-client/3.21.0/confidence-slim/3.20.0)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>Unleash/unleash-client-node</summary>

###
[`v3.21.0`](https://togithub.com/Unleash/unleash-client-node/releases/tag/v3.21.0)

[Compare
Source](https://togithub.com/Unleash/unleash-client-node/compare/v3.20.0...v3.21.0)

#### What's Changed

- fix: getToggle by name may not find the toggle by
[@&#8203;gastonfournier](https://togithub.com/gastonfournier) in
[https://github.com/Unleash/unleash-client-node/pull/455](https://togithub.com/Unleash/unleash-client-node/pull/455)
- chore: release 3.21.0 by
[@&#8203;gastonfournier](https://togithub.com/gastonfournier) in
[https://github.com/Unleash/unleash-client-node/pull/458](https://togithub.com/Unleash/unleash-client-node/pull/458)

#### New Contributors

- [@&#8203;gastonfournier](https://togithub.com/gastonfournier) made
their first contribution in
[https://github.com/Unleash/unleash-client-node/pull/455](https://togithub.com/Unleash/unleash-client-node/pull/455)

**Full Changelog**:
Unleash/unleash-client-node@v3.20.0...v3.21.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://app.renovatebot.com/dashboard#github/Unleash/unleash).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xMTAuMCIsInVwZGF0ZWRJblZlciI6IjM1LjExMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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 this pull request may close these issues.

None yet

5 participants