Skip to content

Commit 42ee640

Browse files
chore: Enhance error handling and user guidance in scripts and documentation
2 parents 774f8bc + 5bbae4c commit 42ee640

File tree

5 files changed

+59
-12
lines changed

5 files changed

+59
-12
lines changed

azure.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ hooks:
1818
run: |
1919
Write-Host "Web app URL: "
2020
Write-Host "$env:WEB_APP_URL" -ForegroundColor Cyan
21-
Write-Host "`nRun the following command in your Bash terminal. It will grant the necessary permissions between resources and your user account, and also process and load the sample data into the application."
21+
Write-Host "`nCreate and activate a virtual environment if not already done, then run the following command in your Bash terminal. It will grant the necessary permissions between resources and your user account, and also process and load the sample data into the application."
2222
Write-Host "bash ./infra/scripts/process_sample_data.sh" -ForegroundColor Cyan
2323
shell: pwsh
2424
continueOnError: false
@@ -28,7 +28,7 @@ hooks:
2828
echo "Web app URL: "
2929
echo $WEB_APP_URL
3030
echo ""
31-
echo "Run the following command in your Bash terminal. It will grant the necessary permissions between resources and your user account, and also process and load the sample data into the application."
31+
echo "Create and activate a virtual environment if not already done, then run the following command in your Bash terminal. It will grant the necessary permissions between resources and your user account, and also process and load the sample data into the application."
3232
echo "bash ./infra/scripts/process_sample_data.sh"
3333
shell: sh
3434
continueOnError: false

documents/DeploymentGuide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ Once you've opened the project in [Codespaces](#github-codespaces), [Dev Contain
253253
- This deployment generally takes **7-10 minutes** to provision the resources in your account and set up the solution.
254254
- If you encounter an error or timeout during deployment, changing the location may help, as there could be availability constraints for the resources.
255255
256-
5. Once the deployment has completed successfully, copy the bash command from terminal: (ex: `bash ./infra/scripts/process_sample_data.sh`) for later use.
256+
5. Once the deployment has completed successfully, continue with the following steps to process and load the sample data.
257257
258258
6. Create and activate a virtual environment in bash terminal:
259259

infra/scripts/copy_kb_files.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,22 @@ if ! az account show &> /dev/null; then
4646
fi
4747

4848
# Check and assign Storage Blob Data Contributor role to current user
49-
signed_user_id=$(az ad signed-in-user show --query id --output tsv)
49+
signed_user_id=$(az ad signed-in-user show --query id --output tsv 2>&1)
50+
if [ -z "$signed_user_id" ] || [[ "$signed_user_id" == *"ERROR"* ]] || [[ "$signed_user_id" == *"InteractionRequired"* ]]; then
51+
echo "✗ Failed to get signed-in user ID. Token may have expired. Re-authenticating..."
52+
az login --use-device-code
53+
signed_user_id=$(az ad signed-in-user show --query id --output tsv)
54+
if [ -z "$signed_user_id" ]; then
55+
echo "✗ Failed to get signed-in user ID after re-authentication"
56+
exit 1
57+
fi
58+
fi
59+
5060
storage_resource_id=$(az storage account show --name "$storageAccountName" --resource-group "$resourceGroupName" --query id --output tsv)
61+
if [ -z "$storage_resource_id" ]; then
62+
echo "✗ Failed to get storage account resource ID"
63+
exit 1
64+
fi
5165

5266
role_assignment=$(MSYS_NO_PATHCONV=1 az role assignment list --assignee $signed_user_id --role "Storage Blob Data Contributor" --scope $storage_resource_id --query "[].roleDefinitionId" -o tsv)
5367
if [ -z "$role_assignment" ]; then

infra/scripts/process_sample_data.sh

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,21 @@ enable_public_access() {
5757
--name "$storageAccountName" \
5858
--resource-group "$resourceGroupName" \
5959
--query "publicNetworkAccess" \
60-
-o tsv)
60+
-o tsv 2>&1)
61+
if [ -z "$original_storage_public_access" ] || [[ "$original_storage_public_access" == *"ERROR"* ]]; then
62+
echo "✗ Failed to get Storage Account public access status"
63+
return 1
64+
fi
65+
6166
original_storage_default_action=$(az storage account show \
6267
--name "$storageAccountName" \
6368
--resource-group "$resourceGroupName" \
6469
--query "networkRuleSet.defaultAction" \
65-
-o tsv)
70+
-o tsv 2>&1)
71+
if [ -z "$original_storage_default_action" ] || [[ "$original_storage_default_action" == *"ERROR"* ]]; then
72+
echo "✗ Failed to get Storage Account network default action"
73+
return 1
74+
fi
6675

6776
if [ "$original_storage_public_access" != "Enabled" ]; then
6877
echo "✓ Enabling Storage Account public access"
@@ -356,7 +365,10 @@ if az account show &> /dev/null; then
356365
else
357366
# Use Azure CLI login if running locally
358367
echo "Authenticating with Azure CLI..."
359-
az login --use-device-code
368+
if ! az login --use-device-code; then
369+
echo "✗ Failed to authenticate with Azure"
370+
exit 1
371+
fi
360372
fi
361373

362374
if check_azd_installed; then
@@ -365,8 +377,12 @@ fi
365377

366378
#check if user has selected the correct subscription
367379
echo ""
368-
currentSubscriptionId=$(az account show --query id -o tsv)
369-
currentSubscriptionName=$(az account show --query name -o tsv)
380+
currentSubscriptionId=$(az account show --query id -o tsv 2>/dev/null)
381+
currentSubscriptionName=$(az account show --query name -o tsv 2>/dev/null)
382+
if [ -z "$currentSubscriptionId" ] || [ -z "$currentSubscriptionName" ]; then
383+
echo "✗ Failed to get current subscription information"
384+
exit 1
385+
fi
370386
if [ "$currentSubscriptionId" != "$azSubscriptionId" ]; then
371387
echo "Current selected subscription is $currentSubscriptionName ( $currentSubscriptionId )."
372388
read -rp "Do you want to continue with this subscription?(y/n): " confirmation
@@ -399,11 +415,17 @@ if [ "$currentSubscriptionId" != "$azSubscriptionId" ]; then
399415
done
400416
else
401417
echo "Proceeding with the current subscription: $currentSubscriptionName ( $currentSubscriptionId )"
402-
az account set --subscription "$currentSubscriptionId"
418+
if ! az account set --subscription "$currentSubscriptionId"; then
419+
echo "✗ Failed to set subscription"
420+
exit 1
421+
fi
403422
fi
404423
else
405424
echo "Proceeding with the subscription: $currentSubscriptionName ( $currentSubscriptionId )"
406-
az account set --subscription "$currentSubscriptionId"
425+
if ! az account set --subscription "$currentSubscriptionId"; then
426+
echo "✗ Failed to set subscription"
427+
exit 1
428+
fi
407429
fi
408430
echo ""
409431

infra/scripts/run_create_index_scripts.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,21 @@ if ! az account show &> /dev/null; then
2828
fi
2929

3030
# Get signed in user and store the output
31-
signed_user=$(az ad signed-in-user show --query "{id:id, displayName:displayName}" -o json)
31+
signed_user=$(az ad signed-in-user show --query "{id:id, displayName:displayName}" -o json 2>&1)
32+
if [[ "$signed_user" == *"ERROR"* ]] || [[ "$signed_user" == *"InteractionRequired"* ]] || [[ "$signed_user" == *"AADSTS"* ]]; then
33+
echo "✗ Failed to get signed-in user. Token may have expired. Re-authenticating..."
34+
az login --use-device-code
35+
signed_user=$(az ad signed-in-user show --query "{id:id, displayName:displayName}" -o json)
36+
fi
37+
3238
signed_user_id=$(echo "$signed_user" | grep -o '"id": *"[^"]*"' | head -1 | sed 's/"id": *"\([^"]*\)"/\1/')
3339
signed_user_display_name=$(echo "$signed_user" | grep -o '"displayName": *"[^"]*"' | sed 's/"displayName": *"\([^"]*\)"/\1/')
3440

41+
if [ -z "$signed_user_id" ] || [ -z "$signed_user_display_name" ]; then
42+
echo "✗ Failed to extract user information after authentication"
43+
exit 1
44+
fi
45+
3546
# Note: Environment variables are now passed as parameters from process_sample_data.sh
3647

3748
### Assign Azure AI User role to the signed in user for AI Foundry ###

0 commit comments

Comments
 (0)