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

Fix issue 377 #475

Merged
merged 4 commits into from Dec 22, 2022
Merged

Fix issue 377 #475

merged 4 commits into from Dec 22, 2022

Conversation

shogo82148
Copy link
Contributor

Issue #, if available:

fixes #377

Description of changes:

rework of #365, but it just accepts context.Context as a first argument.

see #365 (review)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

if argumentType.Kind() != reflect.Interface {
return false, nil
}
if argumentType.NumMethod() == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This check doesn't appear in the case 2: branch, can it be removed?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm guessing this check is to keep handlers like func(event any) {} valid. If that's the case, it's worth adding a comment!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes.
If the first argument is an interface, the handler may be func(event any) or func(ctx context.Context).
We should accept both.

return false, nil
}
if !contextType.Implements(argumentType) || !argumentType.Implements(contextType) {
return false, fmt.Errorf("handler takes an interface, but it is not context.Context: %q", argumentType.Name())
Copy link
Collaborator

@bmoffatt bmoffatt Dec 22, 2022

Choose a reason for hiding this comment

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

Wondering if there's a case where this isn't an error. The trival case is any/interface{}, where the .NumMethod() == 0 check above makes sense. Wondering if the current version of the code panics if the first argument is error, or some other interface with one or more methods (edit) I think of any way that this would be possible with how json.Marshal gets used later, the types it passes in shouldn't have any methods.

@bmoffatt
Copy link
Collaborator

LGTM! Let me know if I understood the .NumMethod() == 0 check correctly and than I can merge this in.

@codecov-commenter
Copy link

codecov-commenter commented Dec 22, 2022

Codecov Report

Merging #475 (c200097) into main (65f8ccd) will increase coverage by 0.32%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #475      +/-   ##
==========================================
+ Coverage   69.74%   70.06%   +0.32%     
==========================================
  Files          21       21              
  Lines        1203     1216      +13     
==========================================
+ Hits          839      852      +13     
  Misses        297      297              
  Partials       67       67              
Impacted Files Coverage Δ
lambda/handler.go 92.76% <100.00%> (+0.67%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@bmoffatt bmoffatt merged commit ad74310 into aws:main Dec 22, 2022
mergify bot pushed a commit to dbsystel/cdk-sops-secrets that referenced this pull request Dec 23, 2022
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [github.com/aws/aws-lambda-go](https://togithub.com/aws/aws-lambda-go) | require | patch | `v1.36.0` -> `v1.36.1` |

---

### Release Notes

<details>
<summary>aws/aws-lambda-go</summary>

### [`v1.36.1`](https://togithub.com/aws/aws-lambda-go/releases/tag/v1.36.1)

[Compare Source](https://togithub.com/aws/aws-lambda-go/compare/v1.36.0...v1.36.1)

##### What's Changed

-   Add additional handler type validations. Fixes issue 377 by [@&#8203;shogo82148](https://togithub.com/shogo82148) in [aws/aws-lambda-go#475

**Full Changelog**: aws/aws-lambda-go@v1.36.0...v1.36.1

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/markussiebert/cdk-sops-secrets).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom context for function handlers result in panic
3 participants