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

Prefer .headOption over .head #435

Merged
merged 1 commit into from
Dec 6, 2024
Merged

Prefer .headOption over .head #435

merged 1 commit into from
Dec 6, 2024

Conversation

davidfurey
Copy link
Member

@davidfurey davidfurey commented Nov 21, 2024

There should always be an element if the main media exists, but we have found one example where this wasn't true in Pre-Publication/Preview content.

This should hopefully fix an issue that we have seen in production (well, preview)

Stack trace that this should avoid:

java.util.NoSuchElementException: head of empty list
	at scala.collection.immutable.Nil$.head(List.scala:663)
	at scala.collection.immutable.Nil$.head(List.scala:662)
	at com.gu.contentapi.client.utils.CapiModelEnrichment$RenderingFormat$.$anonfun$display$4(CapiModelEnrichment.scala:218)
	at scala.Option.map(Option.scala:242)
	at com.gu.contentapi.client.utils.CapiModelEnrichment$RenderingFormat$.$anonfun$display$3(CapiModelEnrichment.scala:217)
	at scala.Option.flatMap(Option.scala:283)
	at com.gu.contentapi.client.utils.CapiModelEnrichment$RenderingFormat$.$anonfun$display$2(CapiModelEnrichment.scala:216)
	at com.gu.contentapi.client.utils.CapiModelEnrichment$RenderingFormat$.$anonfun$display$2$adapted(CapiModelEnrichment.scala:214)
	at com.gu.contentapi.client.utils.CapiModelEnrichment$RenderingFormat$.$anonfun$display$19(CapiModelEnrichment.scala:254)
	at com.gu.contentapi.client.utils.CapiModelEnrichment$RenderingFormat$.$anonfun$display$19$adapted(CapiModelEnrichment.scala:252)
	at com.gu.contentapi.client.utils.CapiModelEnrichment$$anonfun$getFromPredicate$1.applyOrElse(CapiModelEnrichment.scala:18)
	at com.gu.contentapi.client.utils.CapiModelEnrichment$$anonfun$getFromPredicate$1.applyOrElse(CapiModelEnrichment.scala:18)

Main media is not guaranteed to exist, especially in Pre-Publication/Preview content.

This should hopefully fix an issue that we have seen in production (well, preview)
@davidfurey davidfurey requested a review from a team as a code owner November 21, 2024 16:43
Copy link

Test Results

0 tests  ±0   0 ✅ ±0   0s ⏱️ ±0s
0 suites ±0   0 💤 ±0 
0 files   ±0   0 ❌ ±0 

Results for commit f061a26. ± Comparison against base commit 4e1abf1.

@davidfurey davidfurey merged commit fc832e6 into main Dec 6, 2024
2 checks passed
@davidfurey
Copy link
Member Author

Thanks for the review. I'm hoping this might finally be a change that sbt-version-policy considers to be patch only.

@emdash-ie
Copy link
Contributor

emdash-ie commented Dec 6, 2024

Thanks for the review. I'm hoping this might finally be a change that sbt-version-policy considers to be patch only.

🤞🏻👀🤞🏻

@emdash-ie
Copy link
Contributor

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.

2 participants