-
Notifications
You must be signed in to change notification settings - Fork 554
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
Scala 2.13: Refactor cricket match summary template #25345
Conversation
This commit removes duplication in the cricket match summary template, which is embedded into the /sport/cricket/match/.../...-team.json endpoint, delivering a dynamically loaded HTML chunk summarising the scores on to Cricket articles like this: https://www.theguardian.com/sport/live/2022/jul/31/england-v-south-africa-third-mens-t20-live-cricket (the corresponding json endpoint for that article is https://api.nextgen.guardianapps.co.uk/sport/cricket/match/2022-07-31/england-cricket-team.json ...you have to work out the date of the article and then transplant it into the url for the json endpoint) We're removing the duplication because in general DRY (https://en.wikipedia.org/wiki/Don%27t_repeat_yourself) is a good thing, and the intricacies of cricket need as much clarity as possible for non-cricket-following developers! The reason we're looking at this code though (and trying to understand all the cricket-related-logic!) is because of a compilation error when compiling under Scala 2.13. The Scala 2.13 compiler is stricter about non-exhaustive matches in case-pattern-match expression than Scala 2.12 was, and this is actually quite a good thing - note that there was recently a bugfix in this bit of code because an unanticipated case in the PA data caused HTTP 500 errors: #24499 In the case of the `@score()` reusable template block, the Scala 2.13 compiler couldn't verify that all cases were covered - even though `!innings.closed` (meaning the innings are ongoing) is the logical complement of (`innings.declared` + `innings.forfeited` + `innings.allOut`), the compiler couldn't verify that without a knowledge of cricket! It's simpler just to catch all the specific 'closed' cases we care about, and then catch the remaining 'open' case with `case _ =>` to very obviously catch everything that isn't closed. Co-authored-by: Roberto Tyley <roberto.tyley@guardian.co.uk>
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 paired on this!
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.
+1 This all makes sense to me - I remember noticing some of these issues when migrating this UI into DCR - and looking through your changes they all make sense!
Oh, wow, is this functionality all already migrated to DCR?! Looking now at https://www.theguardian.com/sport/live/2022/jul/31/england-v-south-africa-third-mens-t20-live-cricket, I see that it's calling the json endpoint with I think this wasn't the case back in December 2021, because #24499 was a bugfix reacting to problems occurring the non-DCR Frontend implementation, but I guess the work in April 2022 with guardian/dotcom-rendering#4758 switched over to using the DCR implementation... I wonder if we should have just deleted this Frontend implementation rather than fixing it? Will the non-DCR version get called anymore at all do you think? Oh well, in any case, I'm going to merge this just to get the Scala 2.13 compilation error cleared! |
Seen on PROD (merged by @rtyley 16 minutes and 8 seconds ago)
|
Having deployed this to PROD, I'm now puzzled, as the json endpoints - DCR & non DCR - are now both 404. I can't really see how this template change could have caused that?! Should I revert this PR?
|
Oh... and now they're no longer 404, and everything looks fine - I guess this usually happens after deploy?!:
|
Maybe?! Still giving 200 so I think we can keep this change. I have never noticed that before but I have never curled these endpoints after a deployment. It looks like that's the case > I guess this usually happens after deploy |
This commit removes code duplication and fixes Scala 2.13 compilation issues in the cricket match summary template, which is embedded into the
/sport/cricket/match/.../...-team.json
endpoint, delivering a dynamically loaded HTML chunk summarising the scores on to Cricket articles like this:(the corresponding json endpoint for that article is https://api.nextgen.guardianapps.co.uk/sport/cricket/match/2022-07-31/england-cricket-team.json ...you have to work out the date of the article - eg 2022-07-31 - and then transplant it into the url for the json endpoint. Example payload)
We're removing the duplication because in general DRY is a good thing, and the intricacies of cricket need as much clarity as possible for non-cricket-following developers! The reason we're looking at this code though (and trying to understand all the cricket-related-logic!) is because of a compilation error under Scala 2.13.
The Scala 2.13 compiler is stricter about non-exhaustive matches in case-pattern-match expression than Scala 2.12 was, and this is actually a good thing - there was recently a bugfix in this bit of code because an unanticipated case in the PA data caused HTTP 500 errors: #24499
In the case of the
@score()
reusable template block, the Scala 2.13 compiler couldn't verify that all cases were covered - even though!innings.closed
(meaning the innings are ongoing) is the logical complement of (innings.declared
+innings.forfeited
+innings.allOut
), the compiler couldn't verify that without a knowledge of cricket!frontend/sport/app/cricket/views/fragments/cricketMatchSummary.scala.html
Lines 84 to 89 in 5a6f2b9
It's simpler just to catch all the specific 'closed' cases we care about, and then catch the remaining 'open' case with
case _ =>
to very obviously catch everything that isn't closed.