Skip to content

Conversation

benrosen78
Copy link
Contributor

Motivation:

Fix for Issue #580, by making it so that the errorType in failed requests will be the type of the error entity, rather than a hardcoded string of FunctionError. This allows orchestration within step functions that perform retry/catch logic based on different error output types.

Modifications:

At a high level, the issue is that swift-aws-lambda-runtime, when an error is thrown, outputs the errorType as hardcoded to FunctionError. You can see that here:

let errorResponse = ErrorResponse(errorType: Consts.functionError, errorMessage: "\(error)")

This PR changes this for all cases to output the type of the error, rather than the hardcoded string:

let errorResponse = ErrorResponse(errorType: "\(type(of: error))", errorMessage: "\(error)")

Now, I will show 2 examples with this solution:

let runtime = LambdaRuntime {
    (event: Input, context: LambdaContext) in

    enum MyTestErrorType: Error {
        case testError
    }
    
    throw MyTestErrorType.testError
}

// outputs {"errorType":"MyTestErrorType","errorMessage":"testError"}
let dynamoDB: DynamoDB = DynamoDB(client: .init())

let runtime = LambdaRuntime {
    (event: Input, context: LambdaContext) in

    let _ = try await dynamoDB.putItem(DynamoDB.PutItemInput(item: [:], tableName: ""))
    
    return Output()
}

// outputs {"errorType":"AWSClientError","errorMessage":"ValidationError: Length of PutItemInput.tableName (0) is less than minimum allowed value 1."}

…f the error in the response instead of a constant FunctionError
Copy link
Contributor

@sebsto sebsto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a unit test to be sure custom error errors are reported and we're not going to change this behavior in the future.

@sebsto sebsto assigned sebsto and benrosen78 and unassigned sebsto Oct 14, 2025
@sebsto sebsto added good first issue Good for newcomers 🆕 semver/minor Adds new public API. size/S Small task. (A couple of hours of work.) labels Oct 14, 2025
@benrosen78 benrosen78 requested a review from sebsto October 14, 2025 20:36
Copy link
Contributor

@sebsto sebsto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for going the extra mile and adding the test.
If the CI passes, I'll merge and release asap.

Thank you for your first contribution!

}
}

@Test(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great !

@sebsto sebsto enabled auto-merge (squash) October 14, 2025 22:05
@sebsto sebsto disabled auto-merge October 14, 2025 22:06
@sebsto sebsto merged commit 9487a09 into swift-server:main Oct 14, 2025
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

good first issue Good for newcomers 🆕 semver/minor Adds new public API. size/S Small task. (A couple of hours of work.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement support for throwing errors that will result in different ErrorType's

2 participants