Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unclear exception when calling TerminateInstanceAsync on invalid instance #3027

Open
andystaples opened this issue Feb 4, 2025 · 0 comments

Comments

@andystaples
Copy link
Contributor

Description

When calling TerminateInstanceAsync() in dotnet-isolated on an orchestration ID that is already completed, terminated, or otherwise not eligable for termination, you get an RpcException with the following message:
Status(StatusCode="Unknown", Detail="Exception was thrown by handler.")
This is unhelpful and we are losing the detail provided by the exception thrown here:

throw new InvalidOperationException($"Cannot terminate the orchestration instance {instanceId} because instance is in the {state.OrchestrationStatus} state.");

Expected behavior

Terminating an invalid orchestration should throw an exception with a helpful stack trace and error message.

Actual behavior

Terminating a scheduled orchestration throws a generic RpcException.

Relevant source code snippets

        [Function("TerminateInstance")]
        public static async Task<HttpResponseData> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
            [DurableClient] DurableTaskClient client,
            string instanceId)
        {
            string reason = "Long-running orchestration was terminated early.";
            try 
            {
                await client.TerminateInstanceAsync(instanceId, reason);
                return req.CreateResponse(HttpStatusCode.OK);
            }
            catch (RpcException ex) 
            {
                var response = req.CreateResponse(HttpStatusCode.BadRequest);
                response.Headers.Add("Content-Type", "text/plain");
                await response.WriteStringAsync(ex.Message);
                return response;
            }
        }

Known workarounds

None

App Details

Latest Durable worker extension **1.2.2/dotnet-isolated/FunctionsV4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant