Skip to content

Language & number consistency - #90

Merged
justinabrahms merged 7 commits into
open-feature:mainfrom
toddbaert:language-number-consistency
Jun 2, 2022
Merged

justinabrahms merged 7 commits into
open-feature:mainfrom
toddbaert:language-number-consistency

Conversation

@toddbaert

@toddbaert toddbaert commented May 31, 2022 •

Copy link
Copy Markdown
Member

This spec has 2 commits, I strongly suggest you look at them one at a time, since the second is purely whitespace changes.

1st commit:

  • breaks the flag-evaluation.md doc into sections, more like the hooks.md doc, to prevent so much number thrashing in the future
  • improves consistency of terminology across files (see comments)
  • specifies that both error and finally user-defined hooks may throw. This may be controversial, but I think it makes sense (and finally can already throw, as per spec). User-defined code being able to throw seems like a plus too me. See comments.

2nd commit:

  • sets proseWrap: never in prettier. This improves readability in PRs. As it stands, the fact that line-wrapping is on adds a lot of unneeded deltas in commits, since adding a new word might totally change the way the wrapping ends up. If we keep everything to a single line, it makes diffing much easier. This is mentioned in the style guide

Fixes #38

@toddbaert
toddbaert requested a review from oleg-nenashev as a code owner May 31, 2022 19:42
@toddbaert toddbaert changed the title Language number consistency Language & number consistency May 31, 2022
@toddbaert
toddbaert force-pushed the language-number-consistency branch from 42a0463 to 96b5e1d Compare May 31, 2022 19:46
Comment thread specification/flag-evaluation/hooks.md Resolved
Comment thread specification/flag-evaluation/hooks.md Resolved
Comment thread specification/flag-evaluation/hooks.md Resolved
@toddbaert
toddbaert requested a review from InTheCloudDan May 31, 2022 19:51
Comment thread specification.json Resolved
Comment thread specification.json Outdated
"content": "Methods, functions, or operations on the client MUST NOT throw exceptions, or otherwise abnormally terminate. Flag evaluation calls must always return the `default value` in the event of abnormal execution. Exceptions include functions or methods for the purposes for configuration or setup.",
"id": "Requirement 1.4.9",
"machine_id": "requirement_1_4_9",
"content": "Methods, functions, or operations on the client MUST NOT throw exceptions, or otherwise abnormally terminate. Flag evaluation calls must always return the `default value` in the event of abnormal execution. Exceptions include functions or methods for the purposes for configuration or setup, and user-defined code such as hooks.",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I know I keep waffling on this. This makes me a little uneasy. I'm trying to think through the API from a user's perspective and I think we're going to end up with this:

Old

if client.get_boolean('redesign_enabled', false):
  return redesign()
return default()

New

try:
  if client.get_boolean('redesign_enabled', false):
    return redesign()
except Exception:
  return default()
return default()

This looks way less attractive of an API to me. In order to avoid this, we'd have to take on some additional complexity in the client implementation to swallow exceptions even in error hooks & finally hooks. This would mean that users don't get a guarantee that error hooks run (e.g. if error hook 1 throws, then error hook 2 wouldn't get invoked).

That.. kinda seems worth it?

@toddbaert toddbaert Jun 1, 2022 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@justinabrahms

I know I keep waffling on this. This makes me a little uneasy. I'm trying to think through the API from a user's perspective and I think we're going to end up with {reference ugly code}

I'm guilty of waffling too. For now, I feel that at the very least, for simplicity sake, we need to treat finally and error the same (if we allow finally to throw, we allow error to throw).

This would mean that users don't get a guarantee that error hooks run (e.g. if error hook 1 throws, then error hook 2 wouldn't get invoked).

This sort of thing already happens in before/after - if a before hook throws, no other before hooks are executed. I dont think it's too astonishing to assume the same thing would occur in the error handler, but we should define it if we go this way.

On the side of throwing, I would say that error and finally hooks will likely be simple and low-risk enough that they rarely throw. Hooks are also not "SDK-code" proper, but code the app-author adds, which I think we can think about a bit differently from the main SDK functionality (Cloudbees considers "user-space" code "different" from primary SDK code as well, and allows some configuration around the error behavior, see here. I would also recommend that they throw unchecked exceptions, so that in Java, for instance, the compiler won't force you to wrap API calls in a try/catch. Throwing also allows for intentional re-throwing from an error, which might be useful in debugging situations, for instance, when developing a provider.

Lastly, the hooks semantics basically mirror a try/catch. Re-throwing in a catch results in propagation of the exception back up through the stack, and the rest of the catch block not executing. This is analogous to the behavior this PR defines for hooks.

On the side of swallowing... This is objectively the "safer" route. It does also allow us to guarantee all error and finally hooks are executed, and app code will NEVER break, not even if the author writes a really broken hook. I'm not 100% this is the least-astonishing way to go, though.

cc @beeme1mr @agentgonzo

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see your point about hooks being user code. If hooks were "code I wrote", I'd be on board without reservation. When we start pulling in libraries for hooks, I get less sure. Now I need to validate that the hook I'm taking a dependency on isn't going to throw and crash my application, returning 5xx to the user.

I don't have a clear direction forward on this one, just concerns. Happy to defer to the broader consensus.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This sort of thing already happens in before/after - if a before hook throws, no other before hooks are executed. I dont think it's too astonishing to assume the same thing would occur in the error handler, but we should define it if we go this way.

An argument could be made for either approach. However, I think it may be worth considering catching errors so other hooks are still executed. Imagine if you have a hook that modifies context but runs after a misbehaving hook, this would lead to unexpected behavior.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@beeme1mr If a before hook throws an error, the next one would not run and we would not resolve the flag. It would just be the default value with an error value, I believe. I don't think correctness is a big concern.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, that makes sense.

@toddbaert toddbaert Jun 1, 2022 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

When we start pulling in libraries for hooks, I get less sure. Now I need to validate that the hook I'm taking a dependency on isn't going to throw and crash my application, returning 5xx to the user.

Yep, that's a fair point. We do expect some of these to come from third party / a contrib repository. I would feel nervous including such code knowing that it could throw.

@toddbaert toddbaert Jun 1, 2022 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I had another thought - what if a finally involves closing some resource and and an unhanded error results in NOT closing it, and therefor a leak or invalid data? I think at the moment, the safest path is to never throw in error or finally... so swallow everything and run ALL the error and finally hooks. That's the path we can take now to have the least regrets later.

I think if you guys are in agreement, I will update the spec for this. One other relevant issue is https://github.com/open-feature/spec/issues/39. We would likely want to log an error on this interface eventually, even if for now we just print to stderr.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Always run finally and error hooks. Always swallow the errors. I feel good about that.

@toddbaert toddbaert Jun 1, 2022 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Comment thread specification.json Resolved
Comment thread specification/flag-evaluation/hooks.md Resolved
Comment thread specification/flag-evaluation/hooks.md Resolved
@toddbaert
toddbaert requested a review from moredip June 1, 2022 14:58
@toddbaert

Copy link
Copy Markdown
Member Author

@justinabrahms I think I've addressed all your concerns except the big one, which I personally feel unsure about: #90 (comment)

Comment thread specification.json Resolved
Comment thread specification/flag-evaluation/hooks.md Resolved
@toddbaert
toddbaert requested a review from justinabrahms June 1, 2022 18:50
@justinabrahms
justinabrahms merged commit d77e755 into open-feature:main Jun 2, 2022
@toddbaert
toddbaert deleted the language-number-consistency branch June 2, 2022 16:18
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.

Finally hook errors?

3 participants