Skip to content

Commit 947a74f

Browse files
Per Kopsperkops
authored andcommitted
refactor: replace null-forgiving operator with explicit null check
Remove null-forgiving operator (!) in DataReaderExtensions and add defensive null check with descriptive exception. While deserialization failure is unlikely (we control the JSON construction), an explicit check provides better error messages if data corruption or type mapping issues occur.
1 parent 724839a commit 947a74f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Atc.Kusto/Extensions/DataReaderExtensions.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,15 @@ public static T[] ReadObjects<T>(
6767
doc.WriteEndObject();
6868
doc.Flush();
6969

70-
results.Add(JsonSerializer.Deserialize<T>(buffer.WrittenSpan, options)!);
70+
var deserializedObject = JsonSerializer.Deserialize<T>(buffer.WrittenSpan, options);
71+
if (deserializedObject is null)
72+
{
73+
throw new InvalidOperationException(
74+
$"Failed to deserialize DataReader row to type {typeof(T).Name}. " +
75+
$"This may indicate corrupted data or an incompatible type mapping.");
76+
}
77+
78+
results.Add(deserializedObject);
7179
}
7280

7381
return [.. results];

0 commit comments

Comments
 (0)