Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "10.0.102",
"version": "10.0.100",
"rollForward": "latestPatch",
"allowPrerelease": false
}
Expand Down
9 changes: 8 additions & 1 deletion src/PoVicTranslate.Web/Services/TranslationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Maintain the sentiment and intent of the original text.
public TranslationService(
IOptions<ApiSettings> apiSettings,
TelemetryClient telemetryClient,
ILogger<TranslationService> logger)
ILogger<TranslationService> logger,
Comment on lines 32 to +33

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential NullReferenceException:
The constructor does not validate telemetryClient and logger for null. If either is not provided, subsequent usage will result in a runtime exception.

Recommended solution:
Add explicit null checks for these dependencies:

ArgumentNullException.ThrowIfNull(telemetryClient);
ArgumentNullException.ThrowIfNull(logger);

ChatClient? chatClient = null)
{
ArgumentNullException.ThrowIfNull(apiSettings);
_telemetryClient = telemetryClient;
Expand All @@ -39,6 +40,12 @@ public TranslationService(
var settings = apiSettings.Value;
_deploymentName = settings.AzureOpenAIDeploymentName;

if (chatClient != null)
{
_chatClient = chatClient;
return;
}

if (string.IsNullOrWhiteSpace(settings.AzureOpenAIApiKey) ||
string.IsNullOrWhiteSpace(settings.AzureOpenAIEndpoint) ||
string.IsNullOrWhiteSpace(settings.AzureOpenAIDeploymentName))
Comment on lines 41 to 51

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent Configuration Validation:
The validation of Azure OpenAI settings (lines 49-51) is only performed if chatClient is null. However, _deploymentName is always set from settings.AzureOpenAIDeploymentName (line 41), even when chatClient is provided. If this value is null or whitespace, it could cause runtime errors later.

Recommended solution:
Validate settings.AzureOpenAIDeploymentName for null or whitespace regardless of whether chatClient is provided.

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading