Repository navigation
Language & number consistency - #90
Conversation
42a0463 to
96b5e1d
Compare
| "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.", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Always run finally and error hooks. Always swallow the errors. I feel good about that.
There was a problem hiding this comment.
OK, I updated the spec for this: https://github.com/open-feature/spec/pull/90/files#r887159585
|
@justinabrahms I think I've addressed all your concerns except the big one, which I personally feel unsure about: #90 (comment) |
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:
errorandfinallyuser-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:
proseWrap: neverin 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 guideFixes #38