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: gate transformers on valid non-nil destinations #211

Merged
merged 3 commits into from May 24, 2022

Conversation

zaquestion
Copy link
Contributor

@zaquestion zaquestion commented May 18, 2022

This builds on #203 which attempted to provide a more flexible gating to
running transformers. However upon testing #203 in my own environment, I
ran into the first panic listed below.

There are a variety of errors that can happen when trying to run
reflection on zero values:

2 just from my testing of this PR

        panic: reflect: call of reflect.Value.Type on zero Value

        panic: reflect: call of reflect.Value.FieldByName on zero Value

The panic specifically calls out zero values, but it's actual a more
specific set of values which is covered by reflect.IsValid.

I attempted to replace the check with reflect.IsZero, which ends up
being too restrictive and breaks existing tests. I also attempted to
solely use reflect.IsValid which is not restrictive enough and cause
the later panic above in the tests. Thus I arrived on the combination in
this PR which seems to strike the "right" balance.

This builds on imdario#203 which attempted to provide a more flexible gating to
running transformers. However upon testing imdario#203 in my own environment, I
ran into the first panic listed below.

There are a variety of errors that can happen when trying to run
reflection on zero values:

2 just from my testing of this PR
```
        panic: reflect: call of reflect.Value.Type on zero Value

        panic: reflect: call of reflect.Value.FieldByName on zero Value
```
The panic specifically calls out zero values, but it's actual a more
specific set of values which is covered by `reflect.IsValid`.

I attempted to replace the check with `reflect.IsZero`, which ends up
being too restrictive and breaks existing tests. I also attempted to
solely use `reflect.IsZero` which is not restrictive enough and cause
the later panic above in the tests. Thus I arrived on the combination in
this PR which seems to strike the "right" balance.
@sourcelevel-bot
Copy link

sourcelevel-bot bot commented May 18, 2022

Hello, @zaquestion! This is your first Pull Request that will be reviewed by SourceLevel, an automatic Code Review service. It will leave comments on this diff with potential issues and style violations found in the code as you push new commits. You can also see all the issues found on this Pull Request on its review page. Please check our documentation for more information.

@zaquestion
Copy link
Contributor Author

zaquestion commented May 18, 2022

Added a test for the specific panic I alluded to in #203, I had significant trouble reproducing the case my integration tests were hitting so I ultimately settled for adding the test in the way I did as I didn't want it to be left entirely uncovered.

@zaquestion
Copy link
Contributor Author

zaquestion commented May 23, 2022

@imdario Just poking you again as a reminder to peek at this. Hope ya had a lovely weekend

@imdario imdario self-assigned this May 23, 2022
@imdario
Copy link
Owner

imdario commented May 24, 2022

@zaquestion It wasn't as pleasant as I expected. Sorry for the delay. It looks good, all tests are green and the code feels quite right.

@imdario imdario merged commit fd7d2bc into imdario:master May 24, 2022
3 checks passed
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.

None yet

2 participants