-
Notifications
You must be signed in to change notification settings - Fork 50
Update ClientContext.client to allow it to be unset #594
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
base: main
Are you sure you want to change the base?
Conversation
armanbilge
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that there are several other fields that are documented as nullable in the Java documentation. I'm not sure whether we want to fix all these by making them Options in the public API (which would probably mean a major version bump)
Yikes! I guess we should issue it and consider it for a major bump. I took a quick look at the JavaDocs but I don't see where nullability is indicated?
| @deprecated( | ||
| "Use maybeClient, because it's possible this will be populated with empty strings if no client context was received", | ||
| "0.3.2") | ||
| def client: ClientContextClient | ||
| @nowarn("cat=deprecation") | ||
| def maybeClient: Option[ClientContextClient] = Option(client) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this is sealed, I think we could actually (1) leave maybeClient abstract and (2) make client final and move the default implementation here. This might be a bit less awkward since we could implement the deprecated method in terms of the replacement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think a name like clientOption is a bit more discoverable (e.g. auto-completes on client).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought so too, but MiMa says
[error] * abstract method clientOption()scala.Option in class feral.lambda.ClientContext is present only in current version
[error] filter with: ProblemFilters.exclude[ReversedMissingMethodProblem]("feral.lambda.ClientContext.clientOption")
Is that safe to exclude (since it's sealed)?
lambda/js/src/test/scala/feral/lambda/ContextPlatformSuite.scala
Outdated
Show resolved
Hide resolved
| } | ||
| } | ||
|
|
||
| private implicit def optionCompare[A, B]( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like something that should be upstreamed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's probably right. I'll do that in a separate PR.
lambda/js/src/test/scala/feral/lambda/ContextPlatformSuite.scala
Outdated
Show resolved
Hide resolved
| obtained.appVersionName == expected.appVersionName && | ||
| obtained.appVersionCode == expected.appVersionCode && | ||
| obtained.appPackageName == expected.appPackageName | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like a lot of boilerplate (which in theory could also have implementation mistakes), is it really worth it? 😅 versus converting one or two examples and just relying on case class equality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like a lot of boilerplate
Yeah, agreed. 😅 But…
Unless I'm misunderstanding you, we don't have case class equality available here, since the case classes are all private for bincompat reasons.
I tried adding extends Product to our facade traits and then doing something generic, but the names don't match between the facade and our traits, and anyway the changes started to spiral quite a bit.
I tried to encode all the nullable values into the ScalaCheck generators so that we'd see failures if we incorrectly did things like clientContext.client.installationId. I'm open to suggestions, but obviously the previous amount of coverage didn't catch this kind of issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I'm misunderstanding you, we don't have case class equality available here, since the case classes are all private for bincompat reasons.
Well, we always have Object#equals available, and because the implementations are (private) case classes we know that there is a reasonable and correct implementation of equals. So I meant we can just rely on that.
but obviously the previous amount of coverage didn't catch this kind of issue.
No it didn't, but this new amount of coverage also wouldn't catch this kind of issue. Where "this kind of issue" is that the documentation we relied on when originally defining/testing these datatypes did not mention the possibility of nullability/undefinedness.
I tried to encode all the nullable values into the ScalaCheck generators so that we'd see failures
The use of generators lets us capture the combinatorial explosion of values that could be simultaneously nullable (to the best of our knowledge), but I don't feel convinced that the value of this kind of coverage carries its weight in generator boilerplate.
Meanwhile, IMO a more effective kind of coverage is to simply incorporate the linked example from #502 into our test suite.
The JS documentation doesn't mention potential nulls or undefineds, so I guess it's trial and error there. It makes me a little nervous to be making |
Fixes #502.
When I was going through this writing the
ContextPlatformSuites, I noticed that there are several other fields that are documented as nullable in the Java documentation. I'm not sure whether we want to fix all these by making themOptions in the public API (which would probably mean a major version bump), find another way to deal with them, or just leave it alone until someone notices it in practice.