-
Notifications
You must be signed in to change notification settings - Fork 475
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
Comments
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. |
@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 public class CustomError: Exception {
public CustomError(string message)
: base(message) {}
// ...
} |
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. |
@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
Could you share the code snippet for a minimal repro, with code for Lambda function and the exception type? |
@gokarnm 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
}
}
} |
@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. |
@gokarnm Any eta on the fix for this bug? Thanks. |
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.
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? |
Thanks @gokarnm , I will give it a try. |
@gokarnm |
Hi @gokarnm |
The workaround also worked for me. It would be nice if this, and |
The fix for this issue has been deployed to production. |
Is this issue really resolved? i am using |
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. |
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 |
Did you try setting the environment |
Here's the reddit post: https://www.reddit.com/r/aws/comments/98witj/we_are_the_aws_net_team_ask_the_experts/e98xinf |
I have not tried, thought it was temporary fix. I thought default behavior should be unwrapped and that was the fix you put in. |
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. |
According to this example in "AWS Lambda Developer Guide", custom exception can be caught by Step Function State's
Catch
clause usingErrorEquals
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:
While with .Net Core 1.0, it gets the expected one as below:
The text was updated successfully, but these errors were encountered: