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

Run validators with dependencies returning nil #147

Merged
merged 4 commits into from
Nov 10, 2023

Conversation

academo
Copy link
Member

@academo academo commented Nov 10, 2023

The original runner logic will skip validators that have dependencies returning nil.

This was under the idea that validator's dependencies are always required ("hard" dependencies)

Some new validators have "Soft" dependencies which means they can still run some checks even if the dependencies are nil

Additionally the code for many validators was not safe because it was optimistic about the result of the validator's dependencies and could cause panics.

This PR also fixes the code in all the validators that were optimistic about the result of the validator's dependencies.

@academo academo self-assigned this Nov 10, 2023
@@ -22,8 +22,15 @@ var Analyzer = &analysis.Analyzer{
}

func run(pass *analysis.Pass) (interface{}, error) {
metadataBody := pass.ResultOf[metadata.Analyzer].([]byte)
archiveDir := pass.ResultOf[archive.Analyzer].(string)
metadataBody, ok := pass.ResultOf[metadata.Analyzer].([]byte)
Copy link
Member Author

Choose a reason for hiding this comment

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

most of the bulk of the changes in this PR are adding these validations for type castings.

@@ -35,7 +35,7 @@ var Analyzer = &analysis.Analyzer{
func run(pass *analysis.Pass) (interface{}, error) {
metadataBody, ok := pass.ResultOf[metadata.Analyzer].([]byte)
if !ok {
return nil, errors.New("metadata not found")
return nil, nil
Copy link
Member Author

Choose a reason for hiding this comment

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

This change is intended. We don't want to fail the process with this. Instead we should simply skip the validator. the metadata validator is already responsible of reporting this error so this is redundant logic.

@@ -54,6 +61,12 @@ func run(pass *analysis.Pass) (interface{}, error) {
return nil, err
}

_, err = os.Stat(metadataPath)
Copy link
Member Author

Choose a reason for hiding this comment

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

before this would not even execute, now it executes and report a missing plugin.json

@@ -24,7 +23,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
archiveDir, ok := pass.ResultOf[archive.Analyzer].(string)
if !ok || archiveDir == "" {
// this should never happen
return nil, fmt.Errorf("archive dir not found")
return nil, nil
Copy link
Member Author

Choose a reason for hiding this comment

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

Intended. The error should come from the archive validator, this is redundant logic,. we can skip this validator if there's no archive

}
}

// TODO: Is there a better way to skip downstream analyzers than based
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the key change in this PR. removing this logic that skips validators with dependencies returning nil, Now all validators are run

Copy link
Member

@xnyo xnyo left a comment

Choose a reason for hiding this comment

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

Great work! Just one small comment:

pkg/analysis/passes/metadatavalid/metadatavalid.go Outdated Show resolved Hide resolved
Co-authored-by: Giuseppe Guerra <giuseppe.guerra@grafana.com>
@academo academo requested a review from xnyo November 10, 2023 13:08
Copy link
Member

@xnyo xnyo left a comment

Choose a reason for hiding this comment

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

LGTM great work! 🥳

@academo academo merged commit b56d3a1 into main Nov 10, 2023
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
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants