What is the correct way to detect non-existent key in KeyVault - azure

I'm using KeyVaultClient from the 2.3.2 Microsoft.Azure.KeyVault NuGet. Using GetSecretAsync(,), I noticed that a KeyVaultErrorException is raised if I try to access a non-existent secret.
Unfortunately that same error is also raised when access to the keyvault is denied or the keyvault endpoint is not found.
The only distinguisher I see at the moment is the Message property. So what's the right way to detect that a secret was not found? Why would this throw an exception versus returning a null or some other 'empty' object?

Asking for nonexistent secret:
System.AggregateException occurred
HResult=0x80131500
Message=One or more errors occurred.
Source=mscorlib
Inner Exception 1:
KeyVaultErrorException: Secret not found: secret22222
((Microsoft.Azure.KeyVault.Models.KeyVaultErrorException)($exception).InnerException)
.Body.Error.Code = "SecretNotFound"
((Microsoft.Azure.KeyVault.Models.KeyVaultErrorException)($exception).InnerException)
.Body.Error.Message = "Secret not found: secret22222"
No rights for reading secret:
System.AggregateException occurred
HResult=0x80131500
Message=One or more errors occurred.
Source=mscorlib
Inner Exception 1:
KeyVaultErrorException: Access denied
((Microsoft.Azure.KeyVault.Models.KeyVaultErrorException)($exception).InnerException)
.Body.Error.Code = "Forbidden"
((Microsoft.Azure.KeyVault.Models.KeyVaultErrorException)($exception).InnerException)
.Body.Error.Message = "Access denied"
Trying to read a disabled secret:
System.AggregateException occurred
HResult=0x80131500
Message=One or more errors occurred.
Source=mscorlib
Inner Exception 1:
KeyVaultErrorException: Operation get is not allowed on a disabled secret.
((Microsoft.Azure.KeyVault.Models.KeyVaultErrorException)($exception).InnerException)
.Body.Error.Code = "Forbidden"
((Microsoft.Azure.KeyVault.Models.KeyVaultErrorException)($exception).InnerException)
.Body.Error.Message = "Operation get is not allowed on a disabled secret."
Invalid vault endpoint:
System.AggregateException occurred
HResult=0x80131500
Message=One or more errors occurred.
Source=mscorlib
Inner Exception 1:
HttpRequestException: An error occurred while sending the request.
Inner Exception 2:
WebException: The remote name could not be resolved: 'alicezzzzzz.vault.azure.net'
Doesn't look that bad to me. If you're expecting strong error typing, i don't think that's going to happen given the SDK is just light REST wrapper, probably (partially?) generated by AutoRest - not obviously mentioned, but still mentioned :) in the NuGet project description (Project Site).

Related

shaded.databricks.org.apache.hadoop.fs.azure.AzureException: An exception while trying to list a directory after mounting

I am getting below exception,
shaded.databricks.org.apache.hadoop.fs.azure.AzureException: java.util.NoSuchElementException: An error occurred while enumerating the result, check the original exception for details
First I mounted the directory in dbfs like below,
dbutils.fs.mount(
source = f"wasbs://{containerName}#{storageAccount}.blob.core.windows.net/",
mount_point = "/mnt/a",
extra_configs = {f"fs.azure.sas.{containerName}.{storageAccount}.blob.core.windows.net": sasKey}
)
then I did,
dbutils.fs.ls("/mnt/a")
I see below reason,
Caused by: java.util.NoSuchElementException: An error occurred while enumerating the result, check the original exception for details.
at hadoop_azure_shaded.com.microsoft.azure.storage.core.LazySegmentedIterator.hasNext(LazySegmentedIterator.java:113)
at shaded.databricks.org.apache.hadoop.fs.azure.StorageInterfaceImpl$WrappingIterator.hasNext(StorageInterfaceImpl.java:158)
at shaded.databricks.org.apache.hadoop.fs.azure.AzureNativeFileSystemStore.listInternal(AzureNativeFileSystemStore.java:2444)
... 41 more
Caused by: hadoop_azure_shaded.com.microsoft.azure.storage.StorageException: This request is not authorized to perform this operation using this permission.
at hadoop_azure_shaded.com.microsoft.azure.storage.StorageException.translateException(StorageException.java:87)
at hadoop_azure_shaded.com.microsoft.azure.storage.core.StorageRequest.materializeException(StorageRequest.java:305)
at hadoop_azure_shaded.com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:196)
at hadoop_azure_shaded.com.microsoft.azure.storage.core.LazySegmentedIterator.hasNext(LazySegmentedIterator.java:109)
Could someone please help me on this?
This has happened due to wrong SAS key configuration which did not have all permissions for the container. The issue has been resolved after giving right SAS key with all permissions.
The real error this: "This request is not authorized to perform this operation using this permission" - the most probably cause is that you don't have "Blob Contributor" permission that is different from the "Contributor" permission that is set when you create a storage account.

Azure AutoMl error : A field of the entity is over the size limit

I am trying to run an automl code on Azure using the azureml SDK (class AutoMLStep).
But it is throwing an error saying
A field of the entity is over the size limit. FieldName=RunDto.Properties.Value/Length, Limit=550000, Size=697351
ERROR - AutoML driver_wrapper script terminated with an exception of type: <class 'azureml._restclient.exceptions.ServiceException'>
ExceptionTarget: Unspecified 2021-10-05 05:00:02.236 - WARNING - An
service error was raised with an HTTP code 400. Error details
unavailable. 2021-10-05 05:00:02.236 - WARNING - Encountered an
exception of type: <class
'azureml._restclient.exceptions.ServiceException'>, interpreted as
error code Service. 2021-10-05 05:00:02.544 - WARNING - An service
error was raised with an HTTP code 400. Error details unavailable.
2021-10-05 05:00:02.545 - WARNING - Encountered an exception of type:
<class 'azureml._restclient.exceptions.ServiceException'>, interpreted
as error code SystemError.ClientError.AutoMLInternal.Service.
How do I debug this error, to find where is this error exactly pointing to?

is ZONE_RESOURCE_POOL_EXHAUSTED a googleapiclient.errors.httpError?

I am using the googleapiclient(Python) APIs like images().get(), images().insert() etc to list images, create VM instances etc
There were several ZONE_RESOURCE_POOL_EXHAUSTED errors from google cloud last month which caused the following exception in my code
Exception: {'errors': [{'code': 'ZONE_RESOURCE_POOL_EXHAUSTED', 'message': "The zone 'projects/<project-name>/zones/us-central1-b' does not have enough resources available to fulfill the request. Try a different zone, or try again later."}]}
I want to handle this error in my code by sending a unique error code from my server to the client to retry this request after sometime since the error is transient.
I am not able to reproduce this error willfully for the same reason...that its transient
I checked the googleapi code on GitHub at https://github.com/googleapis/google-api-python-client
but couldn't find ZONE_RESOURCE_POOL_EXHAUSTED
I need to verify if its an exception of type "HttpError" or some other class and then can handle it in my code
I am already handling exception of type googleapiclient.errors.HttpError in my code by printing an error message and raising it as urllib.error.HTTPError (the server sends the code e.resp['status'] for this case to the client)
except HttpError as e:
printf('Failed to create %s: %s\n', instanceName,
e._get_reason())
raise HTTPError(
None, int(e.resp['status']), e._get_reason(), "", None)

Microsoft Cognitive Service fails in Azure (trainingApi fails in Azure when instantiated)

I'm using
https://www.nuget.org/packages/Microsoft.Cognitive.CustomVision.Training/1.2.0 on my website.
I using the library to create a new object of TrainingApi like this:
new TrainingApi() {ApiKey = "<API key>"};
This works fine on locally but when published and running in Azure I get this error:
Method not found: 'Void
Microsoft.Cognitive.CustomVision.Training.TrainingApi..ctor(System.Net.Http.DelegatingHandler[])'.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.MissingMethodException: Method not found:
'Void
Microsoft.Cognitive.CustomVision.Training.TrainingApi..ctor(System.Net.Http.DelegatingHandler[])'.
Has anyone any experience with this or know how to solve this issue?

Microsoft CRM Error Report

We created a new organization and trying to use it but we are getting below error. Please give some idea how to resolve/dig this issue.
An unhandled exception occured during the execution of the current web
request.Please review the stack trace for more information about the
error and where it originated in the code.
Error Details: Exception of type 'System.web.HttpUnhandledException'
was thrown.
Thanks

Resources