none
.Net BatchExceptions for Azure Batch

    General discussion

  • Interactions with Azure Batch are made via REST calls.  REST calls communicate success and failure via HTTP status codes and status messages.  Error responses from Azure Batch REST calls often include additional descriptive content helpful in understanding the exact nature of any given failure.

     

    When objects from the namespaces Microsoft.Azure.Batch and Microsoft.Azure.Batch.Protocol are used to make REST calls to the Azure Batch Service, errors are packaged in an instance of the BatchException type and the BatchException is thrown.

     

    The BatchException.RequestInformation property has the extra diagnostic and descriptive content in it.  Of common interest is the RequestResult.BatchError property.  BatchError contains: Code, Message and Values properties.  These three properties carry the specific messages from the server as to the nature of the problem.

     

    Suggestion 1: ToString() is your friend.  BatchException.ToString() will format all of the useful property values into text.  AggregateException.ToString() is less friendly since it does not include the AzureError content.

     

    Suggestion 2: Examine the BatchError properties and the Values collection for specific information.

     

    Here is an example:

     

                    CloudPool pool = client.PoolOperations.CreatePool("mypool", "small", default(CloudServiceConfiguration));

                    try

                    {

                        pool.Commit();

                    }

                    catch (Exception ex)

                    {

                        Console.WriteLine(ex.ToString());

     

                        if (ex is BatchException)

                        {

                            BatchException batchException = ex as BatchException;

                            if (batchException.RequestInformation != null && batchException.RequestInformation.BatchError != null)

                            {

                                Console.WriteLine(batchException.RequestInformation.BatchError.Code);

                                Console.WriteLine(batchException.RequestInformation.BatchError.Message.Value);

                            }

                        }

                    }

     

    The sample attempts to create a pool without filling out the required CloudServiceConfiguration property.  The resulting exception is a BatchException.  This BatchException has an BatchError property that discloses:

     

        Code: MissingRequiredProperty

     

        Message.Value: A required property was not specified in the request body.

     

        Values:

     

            Error Details key=Reason value=One of cloudServiceConfiguration and virtualMachineConfiguration must be specified

     

        From this we can see that the server is telling us that the cloudServiceConfiguration property of the pool is missing and must be set.





    Thursday, October 30, 2014 10:22 PM
    Owner