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: prevent panic on depinject when input or output struct has an un… #12786

Merged

Conversation

JeancarloBarrios
Copy link
Contributor

…exported fild

Description

Closes: #1943


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@JeancarloBarrios JeancarloBarrios marked this pull request as ready for review August 1, 2022 17:48
@JeancarloBarrios JeancarloBarrios requested a review from a team as a code owner August 1, 2022 17:48
Copy link
Member

@aaronc aaronc left a comment

Choose a reason for hiding this comment

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

Would also be good to have errors for unexported fields in Out structs

depinject/struct_args.go Outdated Show resolved Hide resolved
depinject/container_test.go Outdated Show resolved Hide resolved
Co-authored-by: Aaron Craelius <[email protected]>
@codecov
Copy link

codecov bot commented Aug 2, 2022

Codecov Report

Merging #12786 (3869636) into main (07f7035) will increase coverage by 0.70%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #12786      +/-   ##
==========================================
+ Coverage   56.28%   56.98%   +0.70%     
==========================================
  Files         649      661      +12     
  Lines       54955    56088    +1133     
==========================================
+ Hits        30929    31963    +1034     
- Misses      21540    21606      +66     
- Partials     2486     2519      +33     
Impacted Files Coverage Δ
depinject/container.go 90.49% <100.00%> (ø)
depinject/struct_args.go 98.42% <100.00%> (ø)
tx/textual/valuerenderer/valuerenderer.go
errors/handle.go
errors/errors.go
tx/textual/valuerenderer/int.go
tx/textual/valuerenderer/dec.go
tx/textual/valuerenderer/bytes.go
errors/stacktrace.go
errors/abci.go
... and 20 more

@JeancarloBarrios
Copy link
Contributor Author

JeancarloBarrios commented Aug 2, 2022

Hey, @aaronc, @kocubinski, I added the logic for the out struct. However, there is a case where I can't replicate it in testing. Maybe you can guide me. The Out error correction has to happen in two places:
Here the path that is tested in the PR test.:

for i, output := range outputs {
val := reflect.ValueOf(output)
if !val.Elem().CanSet() {
return []reflect.Value{}, fmt.Errorf("depinject.In struct %s on package can't have unexported field", val.String())
}
if !values[i].CanInterface() {
return []reflect.Value{}, fmt.Errorf("depinject.Out struct %s on package can't have unexported field", values[i].String())
}
val.Elem().Set(values[i])
}

However, I have to check here as well because whenever I tested with any module existing keeper, it panics there. I don't know how to manually replicate it in the test, though(for coverage purposes)

if !values[j].CanInterface() {
return reflect.Value{}, 0, fmt.Errorf("depinject.Out struct %s on package %s can't have unexported field", res.Elem().String(), f.PkgPath)
}

@JeancarloBarrios
Copy link
Contributor Author

Hey, @aaronc, @kocubinski, I added the logic for the out struct. However, there is a case where I can't replicate it in testing. Maybe you can guide me. The Out error correction has to happen in two places: Here the path that is tested in the PR test.:

for i, output := range outputs {
val := reflect.ValueOf(output)
if !val.Elem().CanSet() {
return []reflect.Value{}, fmt.Errorf("depinject.In struct %s on package can't have unexported field", val.String())
}
if !values[i].CanInterface() {
return []reflect.Value{}, fmt.Errorf("depinject.Out struct %s on package can't have unexported field", values[i].String())
}
val.Elem().Set(values[i])
}

However, I have to check here as well because whenever I tested with any module existing keeper, it panics there. I don't know how to manually replicate it in the test, though(for coverage purposes)

if !values[j].CanInterface() {
return reflect.Value{}, 0, fmt.Errorf("depinject.Out struct %s on package %s can't have unexported field", res.Elem().String(), f.PkgPath)
}

this has been resolved

@JeancarloBarrios JeancarloBarrios added A:automerge Automatically merge PR once all prerequisites pass. and removed A:automerge Automatically merge PR once all prerequisites pass. labels Aug 2, 2022
@mergify mergify bot merged commit 7103587 into main Aug 3, 2022
@mergify mergify bot deleted the JeancarloBarrios/better-error-for-unexported-fields-in-out branch August 3, 2022 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flesh out ICS0 and specify the API and whether it should be an import or it's own module
3 participants