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 panic when metadata is nil in packagejson analyzer #153

Merged
merged 1 commit into from
Dec 14, 2023

Conversation

xnyo
Copy link
Member

@xnyo xnyo commented Dec 14, 2023

Fixes https://drone.grafana.net/grafana/community-pipeline/1643 when an archive is improperly structured.

Before

panic: interface conversion: interface {} is nil, not []uint8

goroutine 1 [running]:
github.com/grafana/plugin-validator/pkg/analysis/passes/packagejson.run(0xc0030c1580)
	/home/runner/work/plugin-validator/plugin-validator/pkg/analysis/passes/packagejson/packagejson.go:36 +0x36d
github.com/grafana/plugin-validator/pkg/runner.Check.func2(0x19dd680)
	/home/runner/work/plugin-validator/plugin-validator/pkg/runner/runner.go:79 +0x1aa
github.com/grafana/plugin-validator/pkg/runner.Check.func2(0x19dd260)
	/home/runner/work/plugin-validator/plugin-validator/pkg/runner/runner.go:73 +0xd8
github.com/grafana/plugin-validator/pkg/runner.Check({0x19f1c20, 0x23, 0x23}, {0xc0030b7590, 0xf}, {0xc0030fc6e0, 0x19}, {{0x1, {0xc0030b7448, 0x7}, ...}, ...})
	/home/runner/work/plugin-validator/plugin-validator/pkg/runner/runner.go:89 +0x2d7
main.main()
	/home/runner/work/plugin-validator/plugin-validator/pkg/cmd/plugincheck2/main.go:79 +0x7aa

After

{
  "id": "magnesium-wordcloud-panel",
  "version": "1.1.4",
  "plugin-validator": {
    "archive": [
      {
        "Severity": "ok",
        "Title": "Archive is not empty",
        "Detail": "",
        "Name": "empty-archive"
      },
      {
        "Severity": "error",
        "Title": "Archive contains more than one directory",
        "Detail": "Archive should contain only one directory named after plugin id. Found 2 directories",
        "Name": "more-than-one-dir"
      },
      {
        "Severity": "error",
        "Title": "Plugin archive is improperly structured",
        "Detail": "",
        "Context": "Could not find a plugin.json in the expected located. It is possible your plugin archive structure is incorrect.",
        "Name": "zip-invalid"
      }
    ],
    "code-rules": [
      {
        "Severity": "warning",
        "Title": "semgrep not found in PATH",
        "Detail": "",
        "Name": "semgrep-not-found"
      }
    ],
    "go-sec": [
      {
        "Severity": "warning",
        "Title": "gosec not installed",
        "Detail": "Skipping gosec analysis",
        "Name": "go-sec-not-installed"
      }
    ],
    "tzap-gpt": [
      {
        "Severity": "warning",
        "Title": "OPENAI_API_KEY not found in env",
        "Detail": "Skipping tzap installation",
        "Name": "tzap-gpt-install-error"
      }
    ]
  }
}

@xnyo xnyo added the bug Something isn't working label Dec 14, 2023
@xnyo xnyo requested a review from academo December 14, 2023 10:50
@xnyo xnyo self-assigned this Dec 14, 2023

var metadata metadata.Metadata
if err := json.Unmarshal(metadataBody, &metadata); err != nil {
var md metadata.Metadata
Copy link
Member Author

Choose a reason for hiding this comment

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

Not related to this pr, but the previous variable name metadata collided with the metadata package name, which is not ideal

@@ -5,3 +5,4 @@ node_modules/
unpacked_bin/
__debug_bin
config/custom.yaml
.idea
Copy link
Member Author

Choose a reason for hiding this comment

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

not strictly related to this pr either but this is to ignore GoLand's folder

@xnyo xnyo marked this pull request as ready for review December 14, 2023 10:51
@xnyo xnyo requested a review from briangann December 14, 2023 10:51
@xnyo xnyo merged commit e87fc7b into main Dec 14, 2023
3 checks passed
@xnyo xnyo deleted the giuseppe/fix-nil-metadata-in-packagejson branch December 14, 2023 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants