Adds various null checks required for AWS SDK v4#88
Adds various null checks required for AWS SDK v4#88njlr wants to merge 20 commits intofsprojects:masterfrom
Conversation
|
|
||
| if response.IsItemSet then | ||
| return Some response.Item | ||
| return Option.ofObj response.Item |
There was a problem hiding this comment.
I know you're doing it for consistency but the guard guarantees it won't be null (in fact the guard will return Null if the Item.Count = 0)
There was a problem hiding this comment.
Yeah, I had to return an option either way so figured why not.
I guess Some response.Item might be marginally more efficient since it is one fewer null check?
There was a problem hiding this comment.
TL;DR Its more about not putting 'just in case' code that's not justified as that makes the reader have to think more (and/or if you were trying to autogen coverage of all paths, you'd be trying to generate a null with the guard returning true, which would be impossible)
It happens to be more efficient, but its more about keeping the code straightforward and not putting diffs in unless there is an actual correctness improvement - the IsItemSet absolutely guarantees a non-null value, and the general pattern should be to think about guarding all inspections of properties and then either do the work conditionally, or substitute an empty if the arrays are being processed in some way.
| |> Seq.map _.Item | ||
| |> Seq.toArray | ||
| | false, _ -> [||] | ||
| if isNull response.UnprocessedItems then |
There was a problem hiding this comment.
perhaps clearer if we switch to array comprehensions:
let unprocessed =
[| if response.UnprocessedItems <> null then
match response.UnprocessedItems.TryGetValue tableName with
| true, reqs ->
for r in reqs do
if r.PutRequest <> null then
yield r.PutRequest.Item
| false, _ -> () |]
NOTE in the above I did not use isNull / isNotNull
These should normally only be used when you're checking a reference to an F# type that is marked as not allowing null (the default) (to circumvent the compiler error that would arise if you did)
There was a problem hiding this comment.
I like the comprehensions too; updated
| | false, _ -> [||] | ||
| maybeReport | ||
| |> Option.iter (fun r -> r BatchWriteItems (Seq.toList response.ConsumedCapacity) (items.Length - unprocessed.Length)) | ||
| |> Option.iter (fun r -> r BatchWriteItems (if isNull response.ConsumedCapacity then [] else Seq.toList response.ConsumedCapacity) (items.Length - unprocessed.Length)) |
There was a problem hiding this comment.
these get pretty illegible and reformatting might split the lines.
|> Option.iter (fun r ->
let cc = if response.ConsumedCapacity = null then [] else Seq.toList response.ConsumedCapacity
r BatchWriteItems cc (items.Length - unprocessed.Length))
There was a problem hiding this comment.
I will wait till you have made all comments then fix these in one go.
Can also apply Fantomas if it doesn't blow up the diff?
There was a problem hiding this comment.
@njlr we did a big reformat with fantomas last year so it should only update the changes
There was a problem hiding this comment.
these get pretty illegible and reformatting might split the lines.
Much nicer; updated
@njlr we did a big reformat with fantomas last year so it should only update the changes
Great, I have applied Fantomas
| maybeReport | ||
| |> Option.iter (fun r -> | ||
| response.ConsumedCapacity | ||
| (if isNull response.ConsumedCapacity then |
There was a problem hiding this comment.
let cc = if response.ConsumedCapacity = null then [] else Seq.toList response.ConsumedCapacity
for tableName, consumedCapacity in cc |> Seq.groupBy _.TableName do
r tableName Operation.TransactWriteItems (Seq.toList consumedCapacity) (Seq.length transactionItems))
| |> Option.iter (fun r -> r BatchGetItems (List.ofSeq response.ConsumedCapacity) response.Responses[tableName].Count) | ||
| |> Option.iter (fun r -> | ||
| let cc = | ||
| if isNull response.ConsumedCapacity then |
There was a problem hiding this comment.
use = null and/or remove all usage of isNull/isnotNull?
(I really would like this to format as the one liner it should be! did fantomas/auto format do it this way?)
There was a problem hiding this comment.
I find it odd this library defines an isNull when that is part of FSharp.Core 🤔
Will update the rest 👍
Edit:
(I really would like this to format as the one liner it should be! did fantomas/auto format do it this way?)
Yes, that's Fantomas
refactor: remove isNull/isNotNull helpers
This PR adds null checks to
TableContext.fsthat are required for AWS SDK v4.Somewhat related to #87