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 sourcemap validation #102

Merged
merged 1 commit into from
Mar 13, 2023
Merged

Fix sourcemap validation #102

merged 1 commit into from
Mar 13, 2023

Conversation

marefr
Copy link
Member

@marefr marefr commented Mar 13, 2023

Fixing panics by validating sourcemaps are valid. Panic example:

❯ ./bin/linux_amd64/plugincheck2 -config ./config/terse-json.yaml -sourceCodeUri https://github.com/TencentCloud/tencentcloud-monitor-grafana-app ~/Downloads/tencentcloud-monitor-app-2.8.2.zip           
Cloning into '/tmp/validator3743180710'...
remote: Enumerating objects: 436, done.
remote: Counting objects: 100% (436/436), done.
remote: Compressing objects: 100% (356/356), done.
remote: Total 436 (delta 149), reused 274 (delta 69), pack-reused 0
Receiving objects: 100% (436/436), 29.30 MiB | 3.88 MiB/s, done.
Resolving deltas: 100% (149/149), done.
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/grafana/plugin-validator/pkg/sourcemap.ParseSourceMapFromBytes({0xc005680000, 0x83d4f, 0x83d50})
        /home/marcus/go/src/github.com/grafana/plugin-validator/pkg/sourcemap/sourcemap.go:56 +0x22d
github.com/grafana/plugin-validator/pkg/sourcemap.ParseSourceMapFromPath({0xc0053f1100?, 0x1c?})
        /home/marcus/go/src/github.com/grafana/plugin-validator/pkg/sourcemap/sourcemap.go:37 +0x3c
github.com/grafana/plugin-validator/pkg/difftool.CompareSourceMapToSourceCode({0xc0053f1100, 0x35}, {0xc0053e4fe0, 0x1c})
        /home/marcus/go/src/github.com/grafana/plugin-validator/pkg/difftool/difftool.go:42 +0xc5
github.com/grafana/plugin-validator/pkg/analysis/passes/jssourcemap.run(0xc0032c0900)
        /home/marcus/go/src/github.com/grafana/plugin-validator/pkg/analysis/passes/jssourcemap/jssourcemap.go:73 +0x2a6
github.com/grafana/plugin-validator/pkg/runner.Check.func2(0x14cd180)
        /home/marcus/go/src/github.com/grafana/plugin-validator/pkg/runner/runner.go:88 +0x251
github.com/grafana/plugin-validator/pkg/runner.Check({0x14d93a0, 0x20, 0x20}, {0xc0022c0040, 0xe}, {0xc00185ff40, 0x19}, {{0x1, {0xc0022c1478, 0x7}, ...}, ...})
        /home/marcus/go/src/github.com/grafana/plugin-validator/pkg/runner/runner.go:98 +0x2f0
main.main()
        /home/marcus/go/src/github.com/grafana/plugin-validator/pkg/cmd/plugincheck2/main.go:77 +0x7bb

Adding validation to make sure sources and sourcesContent are set and their lengths doesn't mismatch.

With the changes I get the following output:

{                                                                                                                              
  "id": "tencentcloud-monitor-app",                                                                                            
  "version": "2.8.2",                                                                                                          
  "plugin-validator": {
    "go-manifest": [
      {       
        "Severity": "warning",
        "Title": "Could not find or parse Go manifest file",                   
        "Detail": "Your source code contains Go files but there's no Go build manifest. Make sure you are using the latest version of the Go plugin SDK",
        "Name": "no-go-manifest"                                                                                               
      }                                                        
    ],                                                         
    "jsMap": [
      {
        "Severity": "error",
        "Title": "the sourcemap file /tmp/576158446/tencentcloud-monitor-app/module.js.map could not be validated",                                            
        "Detail": "You must include generated source maps for your plugin in your archive file. If you have nested plugins, you must include the source maps fo
r each plugin",                                                
        "Name": "js-map-invalid"                                                                                               
      } 
    ],                                                         
    "legacyplatform": [
      {
        "Severity": "warning",         
        "Title": "module.js: uses legacy plugin platform",                     
        "Detail": "The plugin uses the legacy plugin platform (AngularJS). Please migrate the plugin to use the new plugins platform.",
        "Name": "legacy-platform"                                              
      }                                
    ]                                  
  }                                    
}         

@marefr marefr requested a review from academo March 13, 2023 13:52
@marefr marefr self-assigned this Mar 13, 2023
Copy link
Member

@academo academo left a comment

Choose a reason for hiding this comment

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

Thanks for fixing and adding the tests!

@marefr marefr merged commit f260ac8 into main Mar 13, 2023
@marefr marefr deleted the fix_sourcemap_validation branch March 13, 2023 16:21
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