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
Remove and prevent unchecked type assertions #1245
Conversation
Also add a test.
Whoops, looks like I'll have to put these YAML files in a different directory to prevent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The profit from enabling the type-assertions check seems to be minuscular. We added some checks for little actual benefit. Approved tentatively 🤷♀
@@ -1,6 +1,7 @@ | |||
linters: | |||
auto-fix: false | |||
enable: | |||
- errcheck |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is enabled by default but being explicit is fine
@@ -104,7 +104,10 @@ func (pt PipeTask) Run(ctx Context) (bool, error) { | |||
// 8. - Copy out the pipe files - | |||
log.Printf("PipeTask: %s/%s copying pipe files", ctx.Meta.InstanceNamespace, ctx.Meta.InstanceName) | |||
fs := afero.NewMemMapFs() | |||
pipePod := podObj[0].(*corev1.Pod) | |||
pipePod, ok := podObj[0].(*corev1.Pod) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should never happen since we create that same corev1.Pod
a few lines above it
@@ -451,7 +455,11 @@ func (s *Step) LoadYAML(file string) error { | |||
|
|||
for _, obj := range s.Apply { | |||
if obj.GetObjectKind().GroupVersionKind().Kind == "TestStep" { | |||
s.Step = obj.(*kudo.TestStep) | |||
if testStep, ok := obj.(*kudo.TestStep); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The kind is tested in the line above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but that's orthogonal to the type, as the added test shows. This is the crux of the issue that this PR Fixes:
.
subsetErr := err.(*SubsetError) | ||
subsetErr.AppendPath(iter.Key().String()) | ||
return subsetErr | ||
subsetErr, ok := err.(*SubsetError) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IsSubset
seems to return only SubsetError
s for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. Do you think we should change its signature to return *SubsetError
s instead?
* Enable errcheck with check-type-assertions. * Also add a test for the checked type assertions in LoadYAML. Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
What this PR does / why we need it:
errcheck
to linters and make it report unchecked type assertions.Fixes: #646