{"record":{"id":"641d62732c07a926","repo":"dotnet/runtime","slug":"azure-failed-to-download","errorCode":null,"errorMessage":"Azure failed to download","messagePattern":"Azure failed to download","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/coreclr/scripts/jitutil.py","lineNumber":649,"sourceCode":"    ok = True\n    az_credential = AzureCliCredential()\n    blob = BlobClient.from_blob_url(uri, credential=az_credential)\n    with open(target_location, \"wb\") as my_blob:\n        try:\n            download_stream = blob.download_blob(retry_total=0)\n            try:\n                my_blob.write(download_stream.readall())\n            except Exception as ex1:\n                logging.error(\"Error writing data to %s\", target_location)\n                report_azure_error()\n                ok = False\n        except Exception as ex2:\n            logging.error(\"Azure error downloading %s\", uri)\n            report_azure_error()\n            ok = False\n\n    if not ok and fail_if_not_found:\n        raise RuntimeError(\"Azure failed to download\")\n    return ok\n\n################################################################################\n##\n## File downloading functions\n##\n################################################################################\n\n\ndef download_progress_hook(count, block_size, total_size):\n    \"\"\" A hook for urlretrieve to report download progress\n\n    Args:\n        count (int)               : current block index\n        block_size (int)          : size of a block\n        total_size (int)          : total size of a payload\n    \"\"\"\n    sys.stdout.write(\"\\rDownloading {0:.1f}/{1:.1f} MB...\".format(min(count * block_size, total_size) / 1024 / 1024, total_size / 1024 / 1024))","sourceCodeStart":631,"sourceCodeEnd":667,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/coreclr/scripts/jitutil.py#L631-L667","documentation":"Thrown by download_with_azure() in jitutil.py when an Azure Blob Storage download fails — either during blob.download_blob() (network/auth error) or during writing the downloaded stream to the local file — and fail_if_not_found is True. The function sets ok=False on any exception and raises this error only when the caller requested hard failure.","triggerScenarios":"download_with_azure() creates a BlobClient from the URI, calls blob.download_blob(retry_total=0), and writes the stream to a local file. If either the download (line 636) or the write (line 638) raises, ok is set to False. At line 648-649: if not ok and fail_if_not_found, raise RuntimeError.","commonSituations":"Azure CLI authentication has expired (run 'az login' again). The blob URI is incorrect or the blob was deleted from storage (HTTP 404). Network connectivity issues or firewall blocking Azure endpoints. Insufficient local disk space or permissions to write to target_location. The Azure credentials don't have read access to the specific container/blob.","solutions":["Re-authenticate with Azure CLI: 'az login'.","Verify the blob URI is correct and accessible by opening it in a browser or using 'az storage blob show'.","Check network connectivity to the Azure Storage endpoint.","Verify write permissions and disk space for the target_location path.","If the blob genuinely doesn't exist and that's acceptable, call with fail_if_not_found=False to suppress the error."],"exampleFix":"# before: download fails with auth or 404\nok = download_with_azure(uri, target_location, fail_if_not_found=True)\n\n# after: re-auth and handle not-found gracefully\n# In shell:\naz login\n# In code, if 404 is acceptable:\nok = download_with_azure(uri, target_location, fail_if_not_found=False)","handlingStrategy":"retry","validationCode":"# Verify Azure auth and blob existence before download\nimport subprocess\ndef is_azure_authenticated():\n    result = subprocess.run(['az', 'account', 'show'], capture_output=True)\n    return result.returncode == 0\n\nif not is_azure_authenticated():\n    print('Not authenticated. Run: az login')","typeGuard":"def is_azure_blob_accessible(uri: str) -> bool:\n    # Quick HEAD check via urllib (for anonymous access)\n    import urllib.request\n    try:\n        req = urllib.request.Request(uri, method='HEAD')\n        urllib.request.urlopen(req, timeout=10)\n        return True\n    except Exception:\n        return False","tryCatchPattern":"try:\n    ok = download_with_azure(uri, target_location, fail_if_not_found=True)\nexcept RuntimeError as e:\n    if 'Azure failed to download' in str(e):\n        logging.error('Azure download failed. Check: az login, network, blob existence.')\n        # Optionally retry once after re-auth\n        import subprocess\n        subprocess.run(['az', 'login'])\n        ok = download_with_azure(uri, target_location, fail_if_not_found=False)\n    raise","preventionTips":["Run 'az login' before any Azure Storage download operation.","Verify the blob URI is correct and the blob exists using Azure Storage Explorer or 'az storage blob show'.","Check network connectivity and firewall rules for Azure Storage endpoints.","Ensure write permissions and disk space for the target location.","Use fail_if_not_found=False when 404 is an acceptable outcome."],"tags":["azure","download","network","authentication","jitutil"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}