oxsecurity / megalinter

🦙 MegaLinter analyzes 50 languages, 22 formats, 21 tooling formats, excessive copy-pastes, spelling mistakes and security issues in your repository sources with a GitHub Action, other CI tools or locally.
https://megalinter.io
GNU Affero General Public License v3.0
1.82k stars 214 forks source link

Unexpected error: Cannot read property 'totalFoundErrorNumber' of undefined #712

Closed nsavelyeva closed 2 years ago

nsavelyeva commented 2 years ago

Describe the bug Using GitHub Actions, Groovy linter fails with the below error on every Groovy file: Unexpected error: Cannot read property 'totalFoundErrorNumber' of undefined. Locally this error is not reproduced.

To Reproduce Steps to reproduce the behavior:

  1. Have a maven project with some groovy files.
  2. Create a GitHub Action workflow, in my case I configured the job as follows:

    jobs:
    cancel_duplicates:
    name: Cancel duplicate jobs
    runs-on: ubuntu-latest
    steps:
      - uses: fkirc/skip-duplicate-actions@master
        with:
          github_token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
    
    build:
    name: Mega-Linter src/main
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v2
        with:
          token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
          fetch-depth: 0
    
      - name: Mega-Linter
        id: ml
        uses: nvuillam/mega-linter@v4
        env:
          ENABLE: GROOVY
          GROOVY_NPM_GROOVY_LINT_ARGUMENTS: '--output report/megalinter-src-main.html'
          GROOVY_NPM_GROOVY_LINT_CONFIG_FILE: .groovylintrc-src-main.json
          GROOVY_NPM_GROOVY_LINT_RULES_PATH: conf
          GROOVY_NPM_GROOVY_LINT_FILTER_REGEX_INCLUDE: src/main
          PRINT_ALPACA: false
          VALIDATE_ALL_CODEBASE: true
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  3. Trigger the GitHub Action and wait until it gets completed.
  4. Open checks tab as shown in the screenshot below.
  5. See the totalFoundErrorNumber error on every file

Expected behavior GitHub Actions produce no totalFoundErrorNumber errors, and has the same output as the local execution.

Screenshots Screenshot 2021-09-01 at 11 12 02

Additional context

nvuillam commented 2 years ago

That's a npm-groovy-lint bug :/

I'l also the maintainer of npm-groovy-lint (but i have less available time), i'll have a look !

nsavelyeva commented 2 years ago

An update from my side. Apparently, the error is caused by GROOVY_NPM_GROOVY_LINT_ARGUMENTS option. If I remove it, then GitHub Action workflows work as expected. In my initial description of the issue the local execution command does not have that option and that is why the error is not observed there. But if the option is used (as shown in the command below), then local execution will also be affected with this error.

npx mega-linter-runner -r insiders -e 'ENABLE=GROOVY' -e 'GROOVY_NPM_GROOVY_LINT_FILTER_REGEX_INCLUDE=src/main' -e 'GROOVY_NPM_GROOVY_LINT_CONFIG_FILE=conf/.groovylintrc-src-main.json' -e 'GROOVY_NPM_GROOVY_LINT_RULES_PATH=conf' -e 'GROOVY_NPM_GROOVY_LINT_ARGUMENTS=--output report/megalinter-src-main.html' -e 'PRINT_ALPACA=false' -e 'SHOW_ELAPSED_TIME=true'
GordonJess commented 2 years ago

I'm also having this issue after enabling HTML report output with npm-groovy-lint!

nvuillam commented 2 years ago

@nsavelyeva @GordonJess is it now better with npm-groovy-lint v9.0.0 ?

nsavelyeva commented 2 years ago

Hi @nvuillam, thanks for the response. I executed this command:

npx mega-linter-runner -r insiders -e 'ENABLE=GROOVY' -e 'GROOVY_NPM_GROOVY_LINT_FILTER_REGEX_EXCLUDE=Jenkinsfile.*' -e 'PRINT_ALPACA=false' -e 'SHOW_ELAPSED_TIME=true' -e 'GROOVY_NPM_GROOVY_LINT_ARGUMENTS=--output report/megalinter-src-main.html'

In the output I see it is using v9.0.0: Using [npm-groovy-lint v9.0.0] https://nvuillam.github.io/npm-groovy-lint/ But the error is still reproduced:

GroovyLint: Started CodeNarc Server
GroovyLint: Successfully processed CodeNarc: 
CodeNarc completed: (p1=0; p2=2; p3=11) 4597ms

Unexpected error: Cannot read property 'totalFoundErrorNumber' of undefined
TypeError: Cannot read property 'totalFoundErrorNumber' of undefined
    at NpmGroovyLint.manageReturnCode (/node_modules/npm-groovy-lint/lib/groovy-lint.js:479:49)
    at NpmGroovyLint.postProcess (/node_modules/npm-groovy-lint/lib/groovy-lint.js:328:14)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at async NpmGroovyLint.run (/node_modules/npm-groovy-lint/lib/groovy-lint.js:66:13)
    at async /node_modules/npm-groovy-lint/lib/index.js:12:9
noskovao commented 2 years ago

This issue still exists, I believe it is because no errors were found :) I've tried to fix it locally to check but it is not working or I'm checking in a wrong way:

--- a/lib/codenarc-factory.js
+++ b/lib/codenarc-factory.js
@@ -139,11 +139,11 @@ async function parseCodeNarcResult(options, codeNarcBaseDir, codeNarcJsonResult,

     // Parse main result
     const pckgSummary = codeNarcJsonResult.summary;
-    result.summary.totalFilesWithErrorsNumber = parseInt(pckgSummary.filesWithViolations, 10);
-    result.summary.totalFilesLinted = parseInt(pckgSummary.totalFiles, 10);
-    result.summary.totalFoundErrorNumber = parseInt(pckgSummary.priority1, 10);
-    result.summary.totalFoundWarningNumber = parseInt(pckgSummary.priority2, 10);
-    result.summary.totalFoundInfoNumber = parseInt(pckgSummary.priority3, 10);
+    result.summary.totalFilesWithErrorsNumber = parseInt(pckgSummary.filesWithViolations, 10) || 0;
+    result.summary.totalFilesLinted = parseInt(pckgSummary.totalFiles, 10) || 0;
+    result.summary.totalFoundErrorNumber = parseInt(pckgSummary.priority1, 10) || 0;
+    result.summary.totalFoundWarningNumber = parseInt(pckgSummary.priority2, 10) || 0;
+    result.summary.totalFoundInfoNumber = parseInt(pckgSummary.priority3, 10) || 0;
nvuillam commented 2 years ago

mmmm I think that the solution must be done within npm-groovy-lint instead of Mega-Linter

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

If you think this issue should stay open, please remove the O: stale 🤖 label or comment on the issue.