Unhandled exceptions is being thrown when running a deployment script during build


I am trying to deploy an AWS lambda function using serverless. We have configured a custom step to deploy our package via a serverless template. Note, we have manually installed Serverless in the octopus tentacle where the deployment is run.

We run the following C# deployment script expecting any errors to be caught during the serverless deployment but we are always getting an unhandled error in the attached screenshot. The deployment continues as the lambda function is successfully deployed but we always get this error, therefore each build is treated as a failure. Is there something we are not doing correctly?

Thanks in advanced,


Deployment_Script.txt (1 KB)

Hi Johnny, thanks for reaching out.

The issue most likely comes from an exception inside one of the event handlers assigned to the proc object. Code in these event handlers is not being caught by the try/catch block in your code, so you need to wrap up the event handler code like this:

proc.Exited += (s, e) =>
	try {
		Console.Error.WriteLine("Process exited");
		Console.Error.WriteLine("Exit code: {0}", proc.ExitCode);
	} catch (Exception ex) {
		Console.WriteLine("Exception in Exited");

In particular the Exited event can get called twice under some circumstances, so these additional try/catch blocks will help you narrow down the cause of the problem.

Matt C

thanks Matthew, we were getting the Exited event being called twice for some unknown reason so we have adapted our script to accomodate for this. It is now working as expected.