Fix: add null checks in AIReceiptParser to prevent null reference warnings
Added validation to ensure messageContent is not null or whitespace before deserializing JSON responses from OpenAI and Claude vision APIs. This fixes CS8604 warnings about possible null reference arguments.
This commit is contained in:
@@ -306,6 +306,11 @@ namespace MoneyMap.Services
|
|||||||
messageContent = messageContent.Replace("```json", "").Replace("```", "").Trim();
|
messageContent = messageContent.Replace("```json", "").Replace("```", "").Trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(messageContent))
|
||||||
|
{
|
||||||
|
return new ParsedReceiptData();
|
||||||
|
}
|
||||||
|
|
||||||
var parsedData = JsonSerializer.Deserialize<ParsedReceiptData>(messageContent, new JsonSerializerOptions
|
var parsedData = JsonSerializer.Deserialize<ParsedReceiptData>(messageContent, new JsonSerializerOptions
|
||||||
{
|
{
|
||||||
PropertyNameCaseInsensitive = true
|
PropertyNameCaseInsensitive = true
|
||||||
@@ -388,6 +393,11 @@ namespace MoneyMap.Services
|
|||||||
messageContent = messageContent.Replace("```json", "").Replace("```", "").Trim();
|
messageContent = messageContent.Replace("```json", "").Replace("```", "").Trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(messageContent))
|
||||||
|
{
|
||||||
|
return new ParsedReceiptData();
|
||||||
|
}
|
||||||
|
|
||||||
var parsedData = JsonSerializer.Deserialize<ParsedReceiptData>(messageContent, new JsonSerializerOptions
|
var parsedData = JsonSerializer.Deserialize<ParsedReceiptData>(messageContent, new JsonSerializerOptions
|
||||||
{
|
{
|
||||||
PropertyNameCaseInsensitive = true
|
PropertyNameCaseInsensitive = true
|
||||||
|
|||||||
Reference in New Issue
Block a user