Skip to content

Commit

Permalink
refactor: enhance error messages for Azure tokens 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Nov 14, 2024
1 parent a859378 commit f558bae
Showing 1 changed file with 13 additions and 6 deletions.
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 @@ export class NodeHost implements RuntimeHost {
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,22 +225,27 @@ export class NodeHost implements RuntimeHost {
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 a row, making the second check redundant and potentially leading to unreachable code. Consider refactoring to ensure logical flow and clarity.
if (!tok && this.clientLanguageModel) {
return <LanguageModelConfiguration>{
Expand Down

0 comments on commit f558bae

Please sign in to comment.