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

Exception handling does not work for .Net Core 2.0 for Lambda and Step Functions #211

Closed
mercury-jin-autodesk opened this issue Jan 24, 2018 · 21 comments
Assignees
Labels
bug This issue is a bug.

Comments

@mercury-jin-autodesk
Copy link

According to this example in "AWS Lambda Developer Guide", custom exception can be caught by Step Function State's Catch clause using ErrorEquals with the custom exception type name.

This works for Node.js, .Net Core 1.0. But it does not work for .Net Core 2.0.

With .Net Core 2.0, it gets the following output on the step that throws the custom exception:

{
  "Error": "Lambda.Unknown",
  "Cause": "The cause could not be determined because Lambda did not return an error type."
}

While with .Net Core 1.0, it gets the expected one as below:

{
  "Error": "CustomError",
  "Cause": "{\n  \"errorType\": \"CustomError\",\n  \"errorMessage\": \"This is a custom error!\",\n  \"stackTrace\": [\n    \"at FailFunctionNet.Function.FunctionHandler(String input, ILambdaContext context)\",\n    \"at lambda_method(Closure , Stream , Stream , ContextInfo )\"\n  ]\n}\n"
}
@tsibelman
Copy link

You must return an exception that inherits directly from an exception for some reason. I personally don't understand the reason for this limitation. Also, the handling of exception thrown from async code is suboptimal, there no reason to present aggregate exception and not the real exception.

@mercury-jin-autodesk
Copy link
Author

@tsibelman Return an exception? But throw exception does work for .Net Core 1.0. It does not work for .Net Core 2.0 only. And I do derive from System.Exception for my CustomError

public class CustomError: Exception {
    public CustomError(string message)
        : base(message) {}
    // ...
}

@tsibelman
Copy link

I meant throw sorry, I encounter issue liked your when I used some of the basic exceptions from a framework like ArgumentNullException, but you say it not a case for you.

@gokarnm
Copy link

gokarnm commented Jan 27, 2018

@mercury-jin-autodesk , I'm not able to replicate this issue with .NET Core 2.0. If I throw a custom exception I get the following output from the Lambda function

{
  "errorType": "CustomerNotfoundException",
  "errorMessage": "Abc not found",
  "stackTrace": [
    "at Test.Function.FunctionHandler(String input, ILambdaContext context)",
    "at lambda_method(Closure , Stream , Stream , LambdaContextInternal )"
  ]
}

Could you share the code snippet for a minimal repro, with code for Lambda function and the exception type?

@mercury-jin-autodesk
Copy link
Author

@gokarnm
Running the lambda function directly through Lambda console would result the expected error. But when I connect it into a state machine in Step Functions, the Catch clause does not work only for .Net Core 2.0.

My lambda function codes:

using Amazon.Lambda.Core;
using System;

[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]

namespace FailFunctionNet
{
    public class CustomError: Exception
    {
        public CustomError(string message)
            : base(message)
        {
        }
    }

    public class Function
    {
        public string FunctionHandler(string input, ILambdaContext context)
        {
            throw new CustomError("This is a custom error!");
        }
    }
}

My state machine:

{
  "Comment": "A Catch example of the Amazon States Language using an AWS Lambda Function",
  "StartAt": "HelloWorld",
  "States": {
    "HelloWorld": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:us-east-1:************:function:FailFunctionNet",
      "Catch": [
        {
          "ErrorEquals": ["CustomError"],
          "Next": "CustomErrorFallback"
        },
        {
          "ErrorEquals": ["States.TaskFailed"],
          "Next": "ReservedTypeFallback"
        },
        {
          "ErrorEquals": ["States.ALL"],
          "Next": "CatchAllFallback"
        }
      ],
      "End": true
    },
    "CustomErrorFallback": {
      "Type": "Pass",
      "Result": "This is a fallback from a custom lambda function exception",
      "End": true
    },
    "ReservedTypeFallback": {
      "Type": "Pass",
      "Result": "This is a fallback from a reserved error code",
      "End": true
    },
    "CatchAllFallback": {
      "Type": "Pass",
      "Result": "This is a fallback from a reserved error code",
      "End": true
    }
  }
}

And the result
screenshot-2018-1-29 step functions management console

@gokarnm gokarnm added bug This issue is a bug. and removed Question labels Jan 31, 2018
@gokarnm
Copy link

gokarnm commented Jan 31, 2018

@mercury-jin-autodesk , this is due to a bug in serializing exceptions thrown from a Lambda function. We are working on a fix which should be released soon.

Could you share the response from directly invoking your Lambda function when it throws an exception? There may be a workaround to unblock you while we push the fix.

@mercury-jin-autodesk
Copy link
Author

Running the lambda function directly, and I got the following.

screenshot-2018-1-31 lambda management console

@mabublue
Copy link

mabublue commented Feb 8, 2018

@gokarnm Any eta on the fix for this bug? Thanks.

@gokarnm
Copy link

gokarnm commented Feb 9, 2018

Hi @mercury-jin-autodesk , the workaround is to disable PDB files, the file paths in the error response are not being serialized correctly. You can do this by setting the following in the csproj file.

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
  <DebugType>None</DebugType>
  <DebugSymbols>false</DebugSymbols>
</PropertyGroup>

Hi @mabublue , I'm not able to provide an ETA. This issue is being prioritized and we should release a fix soon. Does the provided workaround help address the issue till we release a fix?

@mabublue
Copy link

Thanks @gokarnm , I will give it a try.

@mercury-jin-autodesk
Copy link
Author

@gokarnm
The workaround works. Thank you.

@mabublue
Copy link

Hi @gokarnm
I have also tried the workaround successfully. Many thanks.

@vellozzi vellozzi self-assigned this Feb 13, 2018
@zaccharles
Copy link
Contributor

The workaround also worked for me. It would be nice if this, and async not returning AggregateException would be fixed. I'm currently manually unwrapping AggregateException before throwing from a synchronous entry point. It's a bit silly.

@vellozzi
Copy link
Contributor

The fix for this issue has been deployed to production.

@laksh-parab
Copy link

Is this issue really resolved? i am using async lambda with .Net core 2.0 and state machine still receiving AggregateException

@normj
Copy link
Member

normj commented Jan 31, 2019

The fix was made in the .NET Core 2.1 runtime. Since Microsoft has put .NET Core 2.0 out of support I would recommend migrating to the .NET Core 2.1 runtime which has long term support.

@laksh-parab
Copy link

My original project was 2.0. I have already converted my project to 2.1 and deployed. still see the same issue. I read same issue posted here

@normj
Copy link
Member

normj commented Jan 31, 2019

Did you try setting the environment UNWRAP_AGGREGATE_EXCEPTIONS to 1 as mentioned in reddit?

@vellozzi
Copy link
Contributor

vellozzi commented Jan 31, 2019

@laksh-parab
Copy link

laksh-parab commented Jan 31, 2019

I have not tried, thought it was temporary fix. I thought default behavior should be unwrapped and that was the fix you put in.

@vellozzi
Copy link
Contributor

We couldn't change the default behavior in the .NET Core 2.1 runtime because it's a breaking change. But we agree, and it will be the default in future versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

8 participants