fluent-kit icon indicating copy to clipboard operation
fluent-kit copied to clipboard

Throw error if @Group key is missing

Open tanner0101 opened this issue 4 years ago • 5 comments

Fixes an issue causing @Group to silently ignore missing data when decoding (#372).

@Group will now throw an error if required data is missing while decoding. This prevents force unwrap issues due to accessing uninitialized values.

Note: It is recommended that you use DTOs to encode/decode your models from your API. Read more here: https://docs.vapor.codes/4.0/fluent/model/#data-transfer-object

tanner0101 avatar Aug 05 '20 21:08 tanner0101

This is technically semver-patch, but the change in behavior of thrown decoding errors could easily break existing error recovery logic, especially given how long this has been broken. Also people may be relying on the "ignores missing keys" behavior by now. Is it worth it to merge this?

gwynne avatar Nov 20 '21 20:11 gwynne

I think it's worth adding. If anyone retrieves the group and then tries to access the property it's gonna fail right?

0xTim avatar Nov 20 '21 22:11 0xTim

I'm actually not sure if you would hit the fatalError() path that way as things stand... if so then it's not a breaking change.

gwynne avatar Nov 20 '21 23:11 gwynne

@gwynne from my experience with fluent-mongo, I believe I ran into fatalError() here.

Joannis avatar Nov 21 '21 09:11 Joannis

Can be easily tested there

Joannis avatar Nov 21 '21 09:11 Joannis