Skip to content

statusoptional: Embed nil check in checkStatusStruct #91

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mandre
Copy link
Contributor

@mandre mandre commented May 22, 2025

Return early from the method when statusType is nil, as we can't reliably expect all callers to check for passed arguments before calling the function.

Hopefully fixes #90

@k8s-ci-robot k8s-ci-robot added do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 22, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mandre
Once this PR has been reviewed and has the lgtm label, please assign joelspeed for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot requested review from jpbetz and sivchari May 22, 2025 06:33
@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label May 22, 2025
Return early from the method when statusType is nil, as we can't
reliably expect all callers to check for passed arguments before calling
the function.

Hopefully fixes kubernetes-sigs#90
@mandre mandre force-pushed the statusoptional-crash branch from 0d8f833 to 3bec636 Compare May 22, 2025 06:34
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label May 22, 2025
@sivchari
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 22, 2025
@JoelSpeed
Copy link
Contributor

Change makes sense, but, do you happen to know which API triggered this? Would be good to be able to add a test case to prevent this regressing in the future

@mandre
Copy link
Contributor Author

mandre commented May 22, 2025

Change makes sense, but, do you happen to know which API triggered this? Would be good to be able to add a test case to prevent this regressing in the future

Sorry, I don't. I've seen the error on https://github.com/k-orc/openstack-resource-controller/ main, if you want to take a look. It's unlikely I'll have a chance to add a regression test this week.

@everettraven
Copy link
Contributor

everettraven commented May 22, 2025

It looks like it is being triggered by

func getStructFromField(pass *analysis.Pass, field *ast.Field) *ast.StructType {
ident, ok := field.Type.(*ast.Ident)
if !ok {
return nil
}
typeSpec, ok := utils.LookupTypeSpec(pass, ident)
if !ok {
return nil
}
structType, ok := typeSpec.Type.(*ast.StructType)
if !ok {
return nil
}
return structType
}
returning nil

This is called when checking structs that are inlined:

// Check embedded structs recursively
a.checkStatusStruct(pass, getStructFromField(pass, childField), markersAccess, jsonTags)

While this change solves the panic, is there an underlying issue here in attempting to grab a struct type from an inlined field?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

statusoptional linter panics
5 participants