Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving error messages on missing tokens #862

Merged
merged 9 commits into from
Nov 14, 2024
19 changes: 13 additions & 6 deletions packages/cli/src/nodehost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@
options
)
if (!azureToken)
throw new Error("Azure OpenAI token not available")
throw new Error(
`Azure OpenAI token not available for ${modelId}`
)
tok.token = "Bearer " + azureToken.token
} else if (
tok.provider === MODEL_PROVIDER_AZURE_SERVERLESS_MODELS
Expand All @@ -223,23 +225,28 @@
tok.azureCredentialsType,
options
)
if (!azureToken) throw new Error("Azure AI token not available")
if (!azureToken)
throw new Error(
`Azure AI token not available for ${modelId}`
)
tok.token = "Bearer " + azureToken.token
}
}
if (!tok) {
if (!modelId)
throw new Error(
"could not determine default model from current configuration"
"Could not determine default model from current configuration"
)
const { provider } = parseModelIdentifier(modelId)
if (provider === MODEL_PROVIDER_AZURE_OPENAI)
throw new Error("Azure OpenAI not configured")
throw new Error(`Azure OpenAI not configured for ${modelId}`)
else if (provider === MODEL_PROVIDER_AZURE_SERVERLESS_OPENAI)
throw new Error("Azure AI OpenAI Serverless not configured")
throw new Error(
`Azure AI OpenAI Serverless not configured for ${modelId}`
)
else if (provider === MODEL_PROVIDER_AZURE_SERVERLESS_MODELS)
throw new Error("Azure AI Models not configured")
throw new Error(`Azure AI Models not configured for ${modelId}`)
}

Check failure on line 249 in packages/cli/src/nodehost.ts

View workflow job for this annotation

GitHub Actions / build

The condition `if (!tok)` is checked twice in succession without any code in between that could modify `tok`. This makes the second check redundant and potentially indicates a logical error in the code flow. Please review the logic to ensure it behaves as intended.

Choose a reason for hiding this comment

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

The condition if (!tok) is checked twice in succession without any code in between that could modify tok. This makes the second check redundant and potentially indicates a logical error in the code flow. Please review the logic to ensure it behaves as intended.

generated by pr-review-commit unreachable_code

if (!tok && this.clientLanguageModel) {
return <LanguageModelConfiguration>{
model: modelId,
Expand Down