UpdateMessage type is problematic
- Dominant language
- Scala
- Stars
- 1.5k
- Forks
- 121
- Avg merge
- 4d 1h
- Merged PRs (30d)
- 29
Description
## Short description
The `UpdateMessage` type contains every possible field an incoming message can have. Because not every message will have every field, each field is an option type. This is less than ideal –
- To understand what messages it's possible to send, you must inspect the [message switch code](https://github.com/guardian/grid/blob/f3820bb7aff920dfc40d3dbe312abbc842ba1c79/thrall/app/lib/kinesis/MessageProcessor.scala#L22).
- To understand the correct combination of fields for a message, you must understand the implementation of each the message handler.
- It's possible to construct badly formed messages at the point of serialisation.
- To handle this proliferation of possible message shapes, [each handler must contain code to extract the appropriate fields](https://github.com/guardian/grid/blob/f3820bb7aff920dfc40d3dbe312abbc842ba1c79/thrall/app/lib/kinesis/MessageProcessor.scala#L71), making handlers more verbose than necessary.
We should use a sum type, and [parse, rather than validating](https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/).
[This PR](https://github.com/guardian/grid/pull/2759) details a possible solution.
Contributor guide
Research direction
Start with thrall/app/lib/kinesis/MessageProcessor.scala, especially the message switch and handler field-extraction code linked in the issue, then review pull request 2759 for the proposed direction. The work is done when UpdateMessage represents valid message shapes directly and handlers no longer extract optional fields from a universal type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100