diff --git a/src/Simulation/EntryPointDriver.Tests/Tests.fs b/src/Simulation/EntryPointDriver.Tests/Tests.fs index 1e00e8bd15b..fdf5a447922 100644 --- a/src/Simulation/EntryPointDriver.Tests/Tests.fs +++ b/src/Simulation/EntryPointDriver.Tests/Tests.fs @@ -929,7 +929,7 @@ let ``Submit has required options`` () = let ``Submit catches exceptions`` () = let given = test "Returns Unit" given submitWithErrorTarget - |> failsWith "Something went wrong when submitting the program to the Azure Quantum service. + |> failsWith "An error occurred when submitting to the Azure Quantum service. This machine always has an error." diff --git a/src/Simulation/EntryPointDriver/Azure/Azure.cs b/src/Simulation/EntryPointDriver/Azure/Azure.cs index 0965e78f212..21b0f931aa6 100644 --- a/src/Simulation/EntryPointDriver/Azure/Azure.cs +++ b/src/Simulation/EntryPointDriver/Azure/Azure.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Immutable; +using System.Reflection; using System.Threading.Tasks; using Microsoft.Azure.Quantum; using Microsoft.Azure.Quantum.Exceptions; @@ -204,6 +205,32 @@ private static async Task SubmitQir( /// The exit code. private static async Task DisplayJobOrError(AzureSettings settings, Task job) { + void DisplayAzureQuantumException(AzureQuantumException ex) => + DisplayError( + "An error occurred when submitting to the Azure Quantum service.", + ex.Message); + + void DisplayQuantumProcessorTranslationException(QuantumProcessorTranslationException ex) => + DisplayError( + "Unable to translate the program for execution on the target quantum machine.", + ex.Message); + + bool HandleTargetInvocationException(TargetInvocationException ex) + { + if (ex.InnerException is AzureQuantumException azureQuantumEx) + { + DisplayAzureQuantumException(azureQuantumEx); + return true; + } + else if (ex.InnerException is QuantumProcessorTranslationException quantumProcessorTranslationEx) + { + DisplayQuantumProcessorTranslationException(quantumProcessorTranslationEx); + return true; + } + + return false; + } + try { DisplayJob(await job, settings.Output); @@ -211,16 +238,20 @@ private static async Task DisplayJobOrError(AzureSettings settings, Task